Part Number Hot Search : 
XX1KTR7 EWR22 1FW42 TGA4832 1623127 2SB1218A 4SXIT AD627
Product Description
Full Text Search
 

To Download PIC16F883T-EPSQTP Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ? 2007 microchip technology inc. preliminary ds41291d pic16f882/883/884/886/887 data sheet 28/40/44-pin, enhanced flash-based 8-bit cmos microcontrollers with nanowatt technology
ds41291d-page ii preliminary ? 2007 microchip technology inc. information contained in this publication regarding device applications and the like is provided only for your convenience and may be superseded by updates. it is your responsibility to ensure that your application meets with your specifications. microchip makes no representations or warranties of any kind whether express or implied, written or oral, statutory or otherwise, related to the information, including but not limited to its condition, quality, performance, merchantability or fitness for purpose . microchip disclaims all liability arising from this information and its use. use of microchip devices in life support and/or safety applications is entirely at the buyer?s risk, and the buyer agrees to defend, indemnify and hold harmless microchip from any and all damages, claims, suits, or expenses resulting from such use. no licenses are conveyed, implicitly or otherwise, under any microchip intellectual property rights. trademarks the microchip name and logo, the microchip logo, accuron, dspic, k ee l oq , k ee l oq logo, micro id , mplab, pic, picmicro, picstart, pro mate, powersmart, rfpic, and smartshunt are registered tr ademarks of microchip technology incorporated in the u.s.a. and other countries. amplab, filterlab, linear active thermistor, migratable memory, mxdev, mxlab, ps logo, seeval, smartsensor and the embedded control solutions company are registered trademarks of micr ochip technology incorporated in the u.s.a. analog-for-the-digital age, appl ication maestro, codeguard, dspicdem, dspicdem.net, dspicworks, ecan, economonitor, fansense, flexrom, fuzzylab, in-circuit serial programming, icsp, icepic, mindi, miwi, mpasm, mplab certified logo, mplib, mplink, pickit, picdem, picdem.net, piclab, pictail, powercal, powerinfo, powermate, powe rtool, real ice, rflab, rfpicdem, select mode, smart serial, smarttel, total endurance, uni/o, wiperlock and zena are trademarks of microchip technology incorporated in the u.s.a. and other countries. sqtp is a service mark of mi crochip technology incorporated in the u.s.a. all other trademarks mentioned herein are property of their respective companies. ? 2007, microchip technology incorporated, printed in the u.s.a., all rights reserved. printed on recycled paper. note the following details of the code protection feature on microchip devices: ? microchip products meet the specification cont ained in their particular microchip data sheet. ? microchip believes that its family of products is one of the mo st secure families of its kind on the market today, when used i n the intended manner and under normal conditions. ? there are dishonest and possibly illegal methods used to breach the code protection feature. all of these methods, to our knowledge, require using the microchip produc ts in a manner outside the operating specif ications contained in microchip?s data sheets. most likely, the person doing so is engaged in theft of intellectual property. ? microchip is willing to work with the customer who is concerned about the integrity of their code. ? neither microchip nor any other semiconductor manufacturer c an guarantee the security of their code. code protection does not mean that we are guaranteeing the product as ?unbreakable.? code protection is constantly evolving. we at microchip are co mmitted to continuously improvi ng the code protection features of our products. attempts to break microchip?s c ode protection feature may be a violation of the digital millennium copyright act. if such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that act. microchip received iso/ts-16949:2002 certification for its worldwide headquarters, design and wafer fabrication facilities in chandler and tempe, arizona, gresham, oregon and mountain view, california. the company?s quality system processes and procedures are for its pic ? mcus and dspic ? dscs, k ee l oq ? code hopping devices, serial eeproms, microperipherals, nonvolatile memory and analog products. in addition, microchip?s quality system for the design and manufacture of development systems is iso 9001:2000 certified.
? 2007 microchip technology inc. preliminary ds41291d-page 1 pic16f882/883/884/886/887 high-performance risc cpu: ? only 35 instructions to learn: - all single-cycle instructions except branches ? operating speed: - dc ? 20 mhz oscillator/clock input - dc ? 200 ns instruction cycle ? interrupt capability ? 8-level deep hardware stack ? direct, indirect and relative addressing modes special microcontroller features: ? precision internal oscillator: - factory calibrated to 1% - software selectable frequency range of 8 mhz to 31 khz - software tunable - two-speed start-up mode - crystal fail detect for critical applications - clock mode switching during operation for power savings ? power-saving sleep mode ? wide operating voltage range (2.0v-5.5v) ? industrial and extended temperature range ? power-on reset (por) ? power-up timer (pwrt) and oscillator start-up timer (ost) ? brown-out reset (bor) with software control option ? enhanced low-current watchdog timer (wdt) with on-chip oscillator (software selectable nominal 268 seconds with full prescaler) with software enable ? multiplexed master clear with pull-up/input pin ? programmable code protection ? high endurance flash/eeprom cell: - 100,000 write flash endurance - 1,000,000 write eeprom endurance - flash/data eeprom retention: > 40 years ? program memory read/write during run time ? in-circuit debugger (on board) low-power features: ? standby current: - 50 na @ 2.0v, typical ? operating current: -11 a @ 32 khz, 2.0v, typical -220 a @ 4 mhz, 2.0v, typical ? watchdog timer current: -1 a @ 2.0v, typical peripheral features: ? 24/35 i/o pins with individual direction control: - high current source/sink for direct led drive - interrupt-on-change pin - individually programmable weak pull-ups - ultra low-power wake-up (ulpwu) ? analog comparator module with: - two analog comparators - programmable on-chip voltage reference (cv ref ) module (% of v dd ) - fixed voltage reference (0.6v) - comparator inputs and outputs externally accessible - sr latch mode - external timer1 gate (count enable) ? a/d converter: - 10-bit resolution and 11/14 channels ? timer0: 8-bit timer/counter with 8-bit programmable prescaler ? enhanced timer1: - 16-bit timer/counter with prescaler - external gate input mode - dedicated low-power 32 khz oscillator ? timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler ? enhanced capture, compare, pwm+ module: - 16-bit capture, max. resolution 12.5 ns - compare, max. resolution 200 ns - 10-bit pwm with 1, 2 or 4 output channels, programmable ?dead time?, max. frequency 20 khz - pwm output steering control ? capture, compare, pwm module: - 16-bit capture, max. resolution 12.5 ns - 16-bit compare, max. resolution 200 ns - 10-bit pwm, max. frequency 20 khz ? enhanced usart module: - supports rs-485, rs-232, and lin 2.0 - auto-baud detect - auto-wake-up on start bit ? in-circuit serial programming tm (icsp tm ) via two pins ? master synchronous serial port (mssp) module supporting 3-wire spi (all 4 modes) and i 2 c? master and slave modes with i 2 c address mask 28/40/44-pin flash-based, 8-bit cmos microcontrollers with nanowatt technology
pic16f882/883/884/886/887 ds41291d-page 2 preliminary ? 2007 microchip technology inc. device program memory data memory i/o 10-bit a/d (ch) eccp/ ccp eusart mssp comparators timers 8/16-bit flash (words) sram (bytes) eeprom (bytes) pic16f882 2048 128 128 28 11 1/1 1 1 2 2/1 pic16f883 4096 256 256 24 11 1/1 1 1 2 2/1 pic16f884 4096 256 256 35 14 1/1 1 1 2 2/1 pic16f886 8192 368 256 24 11 1/1 1 1 2 2/1 pic16f887 8192 368 256 35 14 1/1 1 1 2 2/1
? 2007 microchip technology inc. preliminary ds41291d-page 3 pic16f882/883/884/886/887 pin diagrams ? pic16f882/883/886, 28-pin pdip, soic, ssop table 1: pic16f882/883/886 28-pin summary (pdip, soic, ssop) i/o pin analog comparators timers eccp eusart mssp interrupt pull-up basic ra0 2 an0/ulpwu c12in0- ? ? ? ? ? ? ? ra1 3 an1 c12in1- ? ? ? ? ? ? ? ra2 4 an2 c2in+ ? ? ? ? ? ? v ref -/cv ref ra3 5 an3 c1in+ ? ? ? ? ? ? v ref + ra4 6 ? c1out t0cki ? ? ? ? ? ? ra5 7 an4 c2out ? ? ? ss ?? ? ra6 10 ? ? ? ? ? ? ? ? osc2/clkout ra7 9 ? ? ? ? ? ? ? ? osc1/clkin rb0 21 an12 ? ? ? ? ? ioc/int y ? rb1 22 an10 c12in3- ? p1c ? ? ioc y ? rb2 23 an8 ? ? p1b ? ? ioc y ? rb3 24 an9 c12in2- ? ? ? ? ioc y pgm rb4 25 an11 ? ? p1d ? ? ioc y ? rb5 26 an13 ? t1g ? ? ? ioc y ? rb6 27 ? ? ? ? ? ? ioc y icspclk rb7 28 ? ? ? ? ? ? ioc y icspdat rc0 11 ? ? t1oso/t1cki ? ? ? ? ? ? rc1 12 ? ? t1osi ccp2 ? ? ? ? ? rc2 13 ? ? ? ccp1/p1a ? ? ? ? ? rc3 14 ? ? ? ? ? sck/scl ? ? ? rc4 15 ? ? ? ? ? sdi/sda ? ? ? rc5 16 ? ? ? ? ? sdo ? ? ? rc6 17 ? ? ? ? tx/ck ? ? ? ? rc7 18 ? ? ? ? rx/dt ? ? ? ? re3 1 ? ? ? ? ? ? ? y (1) mclr /v pp ?20 ? ? ? ? ? ? ? ? v dd ? 8 ? ? ? ? ? ? ? ? v ss ?19 ? ? ? ? ? ? ? ? v ss note 1: pull-up activated only with external mclr configuration. 10 11 2 3 4 5 6 1 8 7 9 12 13 14 15 16 17 18 19 20 23 24 25 26 27 28 22 21 pic16f882/883/886 re3/mclr /v pp ra0/an0/ulpwu/c12in0- ra1/an1/c12in1- ra2/an2/v ref -/cv ref /c2in+ ra3/an3/v ref +/c1in+ ra4/t0cki/c1out ra5/an4/ss /c2out v ss ra7/osc1/clkin ra6/osc2/clkout rc0/t1oso/t1cki rc1/t1osi/ccp2 rc2/p1a/ccp1 rc3/sck/scl rb7/icspdat rb6/icspclk rb5/an13/t1g rb4/an11/p1d rb3/an9/pgm/c12in2- rb2/an8/p1b rb1/an10/p1c/c12in3- rb0/an12/int v dd v ss rc7/rx/dt rc6/tx/ck rc5/sdo rc4/sdi/sda 28-pin pdip, soic, ssop
pic16f882/883/884/886/887 ds41291d-page 4 preliminary ? 2007 microchip technology inc. pin diagrams ? pic16f882/883/886, 28-pin qfn 16 2 7 1 3 6 5 4 15 21 19 20 17 18 22 28 26 27 23 24 25 14 8 10 9 13 12 11 pic16f882/883/886 ra1/an1/c12in1- ra0/an0/ulpwu/c12in0- re3/mclr /v pp rb7/icspdat rb6/icspclk rb5/an13/t1g rb4/an11/p1d rc0/t1oso/t1cki rc1/t1osi/ccp2 rc2/p1a/ccp1 rc3/sck/scl rc4/sdi/sda rc5/sdo rc6/tx/ck ra2/an2/v ref -/cv ref /c2in+ ra3/an3/v ref +/c1in+ ra4/t0cki/c1out ra5/an4/ss /c2out v ss ra7/osc1/clkin ra6/osc2/clkout rb3/an9/pgm/c12in2- rb2/an8/p1b rb1/an10/p1c/c12in3- rb0/an12/int v dd v ss rc7/rx/dt 28-pin qfn
? 2007 microchip technology inc. preliminary ds41291d-page 5 pic16f882/883/884/886/887 table 2: pic16f882/883/886 28-pin summary (qfn) i/o pin analog comparators timers eccp eusart mssp interrupt pull-up basic ra0 27 an0/ulpwu c12in0- ? ? ? ? ? ? ? ra1 28 an1 c12in1- ? ? ? ? ? ? ? ra2 1 an2 c2in+ ? ? ? ? ? ? v ref -/cv ref ra3 2 an3 c1in+ ? ? ? ? ? ? v ref + ra4 3 ? c1out t0cki ? ? ? ? ? ? ra5 4 an4 c2out ? ? ? ss ?? ? ra6 7 ? ? ? ? ? ? ? ? osc2/clkout ra7 6 ? ? ? ? ? ? ? ? osc1/clkin rb0 18 an12 ? ? ? ? ? ioc/int y ? rb1 19 an10 c12in3- ? p1c ? ? ioc y ? rb2 20 an8 ? ? p1b ? ? ioc y ? rb3 21 an9 c12in2- ? ? ? ? ioc y pgm rb4 22 an11 ? ? p1d ? ? ioc y ? rb5 23 an13 ? t1g ? ? ? ioc y ? rb6 24 ? ? ? ? ? ? ioc y icspclk rb7 25 ? ? ? ? ? ? ioc y icspdat rc0 8 ? ? t1oso/t1cki ? ? ? ? ? ? rc1 9 ? ? t1osi ccp2 ? ? ? ? ? rc2 10 ? ? ? ccp1/p1a ? ? ? ? ? rc3 11 ? ? ? ? ? sck/scl ? ? ? rc4 12 ? ? ? ? ? sdi/sda ? ? ? rc5 13 ? ? ? ? ? sdo ? ? ? rc6 14 ? ? ? ? tx/ck ? ? ? ? rc7 15 ? ? ? ? rx/dt ? ? ? ? re3 26 ? ? ? ? ? ? ? y (1) mclr /v pp ?17 ? ? ? ? ? ? ? ? v dd ? 5 ? ? ? ? ? ? ? ? v ss ?16 ? ? ? ? ? ? ? ? v ss note 1: pull-up activated only with external mclr configuration.
pic16f882/883/884/886/887 ds41291d-page 6 preliminary ? 2007 microchip technology inc. pin diagrams ? pic16f884/887, 40-pin pdip 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 pic16f884/887 re3/mclr /v pp ra0/an0/ulpwu/c12in0- ra1/an1/c12in1- ra2/an2/v ref -/cv ref /c2in+ ra3/an3/v ref +/c1in+ ra4/t0cki/c1out ra5/an4/ss /c2out re0/an5 re1/an6 re2/an7 v dd v ss ra7/osc1/clkin ra6/osc2/clkout rc0/t1oso/t1cki rc1/t1osi/ccp2 rc2/p1a/ccp1 rc3/sck/scl rd0 rd1 rb7/icspdat rb6/icspclk rb5/an13/t1g rb4/an11 rb3/an9/pgm/c12in2- rb2/an8 rb1/an10/c12in3- rb0/an12/int v dd v ss rd7/p1d rd6/p1c rd5/p1b rd4 rc7/rx/dt rc6/tx/ck rc5/sdo rc4/sdi/sda rd3 rd2 40-pin pdip
? 2007 microchip technology inc. preliminary ds41291d-page 7 pic16f882/883/884/886/887 table 3: pic16f884/887 40-pin summary (pdip) i/o pin analog comparators timers eccp eusart mssp interrupt pull-up basic ra0 2 an0/ulpwu c12in0- ? ? ? ? ? ? ? ra1 3 an1 c12in1- ? ? ? ? ? ? ? ra2 4 an2 c2in+ ? ? ? ? ? ? v ref -/cv ref ra3 5 an3 c1in+ ? ? ? ? ? ? v ref + ra4 6 ? c1out t0cki ? ? ? ? ? ? ra5 7 an4 c2out ? ? ? ss ?? ? ra6 14 ? ? ? ? ? ? ? ? osc2/clkout ra7 13 ? ? ? ? ? ? ? ? osc1/clkin rb0 33 an12 ? ? ? ? ? ioc/int y ? rb1 34 an10 c12in3- ? ? ? ? ioc y ? rb2 35 an8 ? ? ? ? ? ioc y ? rb3 36 an9 c12in2- ? ? ? ? ioc y pgm rb4 37 an11 ? ? ? ? ? ioc y ? rb5 38 an13 ? t1g ? ? ? ioc y ? rb6 39 ? ? ? ? ? ? ioc y icspclk rb7 40 ? ? ? ? ? ? ioc y icspdat rc0 15 ? ? t1oso/t1cki ? ? ? ? ? ? rc1 16 ? ? t1osi ccp2 ? ? ? ? ? rc2 17 ? ? ? ccp1/p1a ? ? ? ? ? rc3 18 ? ? ? ? ? sck/scl ? ? ? rc4 23 ? ? ? ? ? sdi/sda ? ? ? rc5 24 ? ? ? ? ? sdo ? ? ? rc6 25 ? ? ? ? tx/ck ? ? ? ? rc7 26 ? ? ? ? rx/dt ? ? ? ? rd0 19 ? ? ? ? ? ? ? ? ? rd1 20 ? ? ? ? ? ? ? ? ? rd2 21 ? ? ? ? ? ? ? ? ? rd3 22 ? ? ? ? ? ? ? ? ? rd4 27 ? ? ? ? ? ? ? ? ? rd5 28 ? ? ? p1b ? ? ? ? ? rd6 29 ? ? ? p1c ? ? ? ? ? rd7 30 ? ? ? p1d ? ? ? ? ? re0 8 an5 ? ? ? ? ? ? ? ? re1 9 an6 ? ? ? ? ? ? ? ? re2 10 an7 ? ? ? ? ? ? ? ? re3 1 ? ? ? ? ? ? ? y (1) mclr /v pp ? 11 ? ? ? ? ? ? ? ? v dd ?32 ? ? ? ? ? ? ? ? v dd ? 12 ? ? ? ? ? ? ? ? v ss ?31 ? ? ? ? ? ? ? ? v ss note 1: pull-up activated only with external mclr configuration.
pic16f882/883/884/886/887 ds41291d-page 8 preliminary ? 2007 microchip technology inc. pin diagrams ? pic16f884/887, 44-pin qfn 44-pin qfn 10 11 2 3 6 1 18 19 20 21 22 12 13 14 15 38 8 7 44 43 42 41 40 39 16 17 29 30 31 32 33 23 24 25 26 27 28 36 34 35 9 37 5 4 pic16f884/887 ra6/osc2/clkout ra7/osc1/clkin v ss v ss nc v dd re2/an7 re1/an6 re0/an5 ra5/an4/ss /c2out ra4/t0cki/c1out rc7/rx/dt rd4 rd5/p1b rd6/p1c rd7/p1d v ss v dd v dd rb0/an12/int rb1/an10/c12in3- rb2/an8 rb3/an9/pgm/c12in2- nc rb4/an11 rb5/an13/t1g rb6/icspclk rb7/icspdat re3/mclr /v pp ra0/an0/ulpwu/c12in0- ra1/an1/c12in1- ra2/an2/v ref -/cv ref /c2in+ ra3/an3//v ref +/c1in+ rc6/tx/ck rc5/sdo rc4/sdi/sda rd3 rd2 rd1 rd0 rc3/sck/scl rc2/p1a/ccp1 rc1/t1osci/ccp2 rc0/t1oso/t1cki
? 2007 microchip technology inc. preliminary ds41291d-page 9 pic16f882/883/884/886/887 table 4: pic16f884/887 44-pin summary (qfn) i/o pin analog comparators timers eccp eusart mssp interrupt pull-up basic ra0 19 an0/ulpwu c12in0- ? ? ? ? ? ? ? ra1 20 an1 c12in1- ? ? ? ? ? ? ? ra2 21 an2 c2in+ ? ? ? ? ? ? v ref -/cv ref ra3 22 an3 c1in+ ? ? ? ? ? ? v ref + ra4 23 ? c1out t0cki ? ? ? ? ? ? ra5 24 an4 c2out ? ? ? ss ?? ? ra6 33 ? ? ? ? ? ? ? ? osc2/clkout ra7 32 ? ? ? ? ? ? ? ? osc1/clkin rb0 9 an12 ? ? ? ? ? ioc/int y ? rb1 10 an10 c12in3- ? ? ? ? ioc y ? rb2 11 an8 ? ? ? ? ? ioc y ? rb3 12 an9 c12in2- ? ? ? ? ioc y pgm rb4 14 an11 ? ? ? ? ? ioc y ? rb5 15 an13 ? t1g ? ? ? ioc y ? rb6 16 ? ? ? ? ? ? ioc y icspclk rb7 17 ? ? ? ? ? ? ioc y icspdat rc0 34 ? ? t1oso/t1cki ? ? ? ? ? ? rc1 35 ? ? t1osi ccp2 ? ? ? ? ? rc2 36 ? ? ? ccp1/p1a ? ? ? ? ? rc3 37 ? ? ? ? ? sck/scl ? ? ? rc4 42 ? ? ? ? ? sdi/sda ? ? ? rc5 43 ? ? ? ? ? sdo ? ? ? rc6 44 ? ? ? ? tx/ck ? ? ? ? rc7 1 ? ? ? ? rx/dt ? ? ? ? rd0 38 ? ? ? ? ? ? ? ? ? rd1 39 ? ? ? ? ? ? ? ? ? rd2 40 ? ? ? ? ? ? ? ? ? rd3 41 ? ? ? ? ? ? ? ? ? rd4 2 ? ? ? ? ? ? ? ? ? rd5 3 ? ? ? p1b ? ? ? ? ? rd6 4 ? ? ? p1c ? ? ? ? ? rd7 5 ? ? ? p1d ? ? ? ? ? re0 25 an5 ? ? ? ? ? ? ? ? re1 26 an6 ? ? ? ? ? ? ? ? re2 27 an7 ? ? ? ? ? ? ? ? re3 18 ? ? ? ? ? ? ? y (1) mclr /v pp ? 7 ? ? ? ? ? ? ? ? v dd ?8 ? ? ? ? ? ? ? ? v dd ? 28 ? ? ? ? ? ? ? ? v dd ?6 ? ? ? ? ? ? ? ? v ss ? 30 ? ? ? ? ? ? ? ? v ss ?31 ? ? ? ? ? ? ? ? v ss ? 13 ? ? ? ? ? ? ? ? nc (no connect) ? 29 ? ? ? ? ? ? ? ? nc (no connect) note 1: pull-up activated only with external mclr configuration.
pic16f882/883/884/886/887 ds41291d-page 10 preliminary ? 2007 microchip technology inc. pin diagrams ? pic16f884/887, 44-pin tqfp 44-pin tqfp 10 11 2 3 6 1 18 19 20 21 22 12 13 14 15 38 8 7 44 43 42 41 40 39 16 17 29 30 31 32 33 23 24 25 26 27 28 36 34 35 9 37 5 4 pic16f884/887 nc rc0/t1oso/t1cki ra6/osc2/clkout ra7/osc1/clkin v ss v dd re2/an7 re1/an6 re0/an5 ra5/an4/ss /c2out ra4/t0cki/c1out rc7/rx/dt rd4 rd5/p1b rd6/p1c rd7/p1d v ss v dd rb0/an12/int rb1/an10/c12in3- rb2/an8 rb3/an9/pgm/c12in2- nc nc rb4/an11 rb5/an13/t1g rb6/icspclk rb7/icspdat re3/mclr /v pp ra0/an0/ulpwu/c12in0- ra1/an1/c12in1- ra2/an2/v ref -/cv ref /c2in+ ra3/an3//v ref +/c1in+ rc6/tx/ck rc5/sdo rc4/sdi/sda rd3 rd2 rd1 rd0 rc3/sck/scl rc2/p1a/ccp1 rc1/t1osci/ccp2 nc
? 2007 microchip technology inc. preliminary ds41291d-page 11 pic16f882/883/884/886/887 table 5: pic16f884/887 44-pin summary (tqfp) i/o pin analog comparators timers eccp eusart mssp interrupt pull-up basic ra0 19 an0/ulpwu c12in0- ? ? ? ? ? ? ? ra1 20 an1 c12in1- ? ? ? ? ? ? ? ra2 21 an2 c2in+ ? ? ? ? ? ? v ref -/cv ref ra3 22 an3 c1in+ ? ? ? ? ? ? v ref + ra4 23 ? c1out t0cki ? ? ? ? ? ? ra5 24 an4 c2out ? ? ? ss ?? ? ra6 31 ? ? ? ? ? ? ? ? osc2/clkout ra7 31 ? ? ? ? ? ? ? ? osc1/clkin rb0 8 an12 ? ? ? ? ? ioc/int y ? rb1 9 an10 c12in3- ? ? ? ? ioc y ? rb2 10 an8 ? ? ? ? ? ioc y ? rb3 11 an9 c12in2- ? ? ? ? ioc y pgm rb4 14 an11 ? ? ? ? ? ioc y ? rb5 15 an13 ? t1g ? ? ? ioc y ? rb6 16 ? ? ? ? ? ? ioc y icspclk rb7 17 ? ? ? ? ? ? ioc y icspdat rc0 32 ? ? t1oso/t1cki ? ? ? ? ? ? rc1 35 ? ? t1osi ccp2 ? ? ? ? ? rc2 36 ? ? ? ccp1/p1a ? ? ? ? ? rc3 37 ? ? ? ? ? sck/scl ? ? ? rc4 42 ? ? ? ? ? sdi/sda ? ? ? rc5 43 ? ? ? ? ? sdo ? ? ? rc6 44 ? ? ? ? tx/ck ? ? ? ? rc7 1 ? ? ? ? rx/dt ? ? ? ? rd0 38 ? ? ? ? ? ? ? ? ? rd1 39 ? ? ? ? ? ? ? ? ? rd2 40 ? ? ? ? ? ? ? ? ? rd3 41 ? ? ? ? ? ? ? ? ? rd4 2 ? ? ? ? ? ? ? ? ? rd5 3 ? ? ? p1b ? ? ? ? ? rd6 4 ? ? ? p1c ? ? ? ? ? rd7 5 ? ? ? p1d ? ? ? ? ? re0 25 an5 ? ? ? ? ? ? ? ? re1 26 an6 ? ? ? ? ? ? ? ? re2 27 an7 ? ? ? ? ? ? ? ? re3 18 ? ? ? ? ? ? ? y (1) mclr /v pp ? 7 ? ? ? ? ? ? ? ? v dd ?28 ? ? ? ? ? ? ? ? v dd ? 6 ? ? ? ? ? ? ? ? v ss ? 13 ? ? ? ? ? ? ? ? nc (no connect) ? 29 ? ? ? ? ? ? ? ? v ss ? 34 ? ? ? ? ? ? ? ? nc (no connect) ? 33 ? ? ? ? ? ? ? ? nc (no connect) ? 12 ? ? ? ? ? ? ? ? nc (no connect) note 1: pull-up activated only with external mclr configuration.
pic16f882/883/884/886/887 ds41291d-page 12 preliminary ? 2007 microchip technology inc. table of contents 1.0 device overview ............................................................................................................. ........................................................... 13 2.0 memory organization ......................................................................................................... ........................................................ 21 3.0 i/o ports ................................................................................................................... .................................................................. 39 4.0 oscillator module (with fail-safe clock monitor)............................................................................ ........................................... 61 5.0 timer0 module ............................................................................................................... ............................................................ 73 6.0 timer1 module with gate control............................................................................................. .................................................. 76 7.0 timer2 module ............................................................................................................... ............................................................ 81 8.0 comparator module........................................................................................................... ......................................................... 83 9.0 analog-to-digital converter (adc) module .................................................................................... ............................................ 99 10.0 data eeprom and flash program memory control ............................................................................... ................................ 111 11.0 enhanced capture/compare/pwm module ........................................................................................ ..................................... 123 12.0 enhanced universal synchronous asynchronous receiver transmitter (eusart) .................................................. ............. 149 13.0 master synchronous serial port (mssp) module ............................................................................... ..................................... 175 14.0 special features of the cpu ................................................................................................ .................................................... 205 15.0 instruction set summary .................................................................................................... ...................................................... 225 16.0 development support........................................................................................................ ....................................................... 235 17.0 electrical specifications.................................................................................................. .......................................................... 239 18.0 dc and ac characteristics graphs and tables ................................................................................ ....................................... 261 19.0 packaging information...................................................................................................... ........................................................ 263 appendix a: data sheet revision history........................................................................................ .................................................. 273 appendix b: migrating from other pic? devices .................................................................................. ............................................. 273 index .......................................................................................................................... ........................................................................ 275 the microchip web site ......................................................................................................... ............................................................ 283 customer change notification service ........................................................................................... ................................................... 283 customer support ............................................................................................................... ............................................................... 283 reader response ................................................................................................................ .............................................................. 284 product identification system.................................................................................................. ........................................................... 285 to our valued customers it is our intention to provide our valued customers with the bes t documentation possible to ensure successful use of your micro chip products. to this end, we will continue to improve our publications to better suit your needs. our publications will be refined and enhanced as new volumes and updates are introduced. if you have any questions or comments regarding this publication, please contact the marketing communications department via e- mail at docerrors@microchip.com or fax the reader response form in the back of this data sheet to (480) 792-4150. we wel- come your feedback. most current data sheet to obtain the most up-to-date version of this data s heet, please register at our worldwide web site at: http://www.microchip.com you can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page . the last character of the literature number is the vers ion number, (e.g., ds30000a is version a of document ds30000). errata an errata sheet, describing minor operational differences from the data sheet and recommended workarounds, may exist for curren t devices. as device/documentation issues bec ome known to us, we will publish an errata sheet. the errata will specify the revisi on of silicon and revision of document to which it applies. to determine if an errata sheet exists for a particul ar device, please check with one of the following: ? microchip?s worldwide web site; http://www.microchip.com ? your local microchip sales office (see last page) when contacting a sales office, please specify which device, re vision of silicon and data sheet (include literature number) you are using. customer notification system register on our web site at www.microchip.com to receive the most current information on all of our products.
? 2007 microchip technology inc. preliminary ds41291d-page 13 pic16f882/883/884/886/887 1.0 device overview the pic16f882/883/884/886/887 is covered by this data sheet. the pic16f882/883/886 is available in 28- pin pdip, soic, ssop and qfn packages. the pic16f884/887 is available in a 40-pin pdip and 44- pin qfn and tqfp packages. figure 1-1 shows the block diagram of pic16f882/883/886 and figure 1-2 shows a block diagram of the pic16f884/887 device. table 1-1 and table 1-2 show the corresponding pinout descriptions.
pic16f882/883/884/886/887 ds41291d-page 14 preliminary ? 2007 microchip technology inc. figure 1-1: pic16f882/883/886 block diagram flash program memory 13 data bus 8 program bus instruction reg program counter ram file registers direct addr 7 ram addr 9 addr mux indirect addr fsr reg status reg mux alu w reg instruction decode & control timing generation osc1/clkin osc2/clkout 8 8 8 3 8-level stack 128 (2) /256 (1) / 2k (2) /4k (1) / (13-bit) power-up timer oscillator start-up timer power-on reset watchdog timer mclr v ss brown-out reset timer0 timer1 data eeprom 128 (2) / eedata eeaddr t0cki t1cki configuration internal oscillator t1g v dd 8 timer2 eccp block 2 analog comparators v ref + and reference analog-to-digital converter (adc) an0 an1 an2 an3 an4 an8 an9 an10 an11 an12 an13 c1in+ c12in0- c12in1- c12in2- c12in3- c1out c2in+ c2out ccp1/p1a p1b p1c p1d porta portc rc0 rc1 rc2 rc3 rc4 rc5 rc6 rc7 portb eusart tx/ck rx/dt porte re3 ra0 ra1 ra2 ra3 ra4 ra5 ra6 ra7 rb0 rb1 rb2 rb3 rb4 rb5 rb6 rb7 timer1 32 khz oscillator master synchronous serial port (mssp) ccp2 ccp2 sdo sdi/sda sck/scl ss v ref - 14 note 1: pic16f883 only. 2: pic16f882 only. v ref + v ref - cv ref in-circuit debugger (icd) t1osi t1oso 8k x 14 368 bytes 256 bytes
? 2007 microchip technology inc. preliminary ds41291d-page 15 pic16f882/883/884/886/887 figure 1-2: pic16f884/ pic16f887 block diagram portd rd0 rd1 rd2 rd3 rd4 rd5 rd6 rd7 flash program memory 13 data bus 8 program bus instruction reg program counter ram file registers direct addr 7 ram addr 9 addr mux indirect addr fsr reg status reg mux alu w reg instruction decode & control timing generation osc1/clkin osc2/clkout 8 8 8 3 8-level stack 256 (1) /368 bytes 4k (1) /8k x 14 (13-bit) power-up timer oscillator start-up timer power-on reset watchdog timer mclr v ss brown-out reset timer0 timer1 data eeprom 256 bytes eedata eeaddr t0cki t1cki configuration internal oscillator t1g v dd 8 timer2 eccp block 2 analog comparators and reference analog-to-digital converter (adc) an0 an1 an2 an3 an4 an5 an6 an7 an8 an9 an10 an11 an12 an13 porta portc rc0 rc1 rc2 rc3 rc4 rc5 rc6 rc7 portb eusart porte ra0 ra1 ra2 ra3 ra4 ra5 ra6 ra7 rb0 rb1 rb2 rb3 rb4 rb5 rb6 rb7 timer1 32 khz oscillator master synchronous serial port (mssp) ccp2 ccp2 14 note 1: pic16f884 only. re0 re1 re2 re3 sdo sdi/sda sck/scl ss ccp1/p1a p1b p1c p1d tx/ck rx/dt v ref + v ref - v ref + v ref - cv ref c1in+ c12in0- c12in1- c12in2- c12in3- c1out c2in+ c2out in-circuit debugger (icd) t1osi t1oso
pic16f882/883/884/886/887 ds41291d-page 16 preliminary ? 2007 microchip technology inc. table 1-1: pic16f882/883/886 pinout description name function input type output type description ra0/an0/ulpwu/c12in0- ra0 ttl cmos general purpose i/o. an0 an ? a/d channel 0 input. ulpwu an ? ultra low-power wake-up input. c12in0- an ? comparator c1 or c2 negative input. ra1/an1/c12in1- ra1 ttl cmos general purpose i/o. individually enabled pull-up. an1 an ? a/d channel 1 input. c12in1- an ? comparator c1 or c2 negative input. ra2/an2/v ref -/cv ref /c2in+ ra2 ttl cmos general purpose i/o. an2 an ? a/d channel 2. v ref - an ? a/d negative voltage reference input. cv ref ? an comparator voltage reference output. c2in+ an ? comparator c2 positive input. ra3/an3/v ref +/c1in+ ra3 ttl ? general purpose i/o. an3 an ? a/d channel 3. v ref + an ? programming voltage. c1in+ an ? comparator c1 positive input. ra4/t0cki/c1out ra4 ttl cmos general purpose i/o. individually enabled pull-up. t0cki st ? timer0 clock input. c1out ? cmos comparator c1 output. ra5/an4/ss /c2out ra5 ttl cmos general purpose i/o. an4 an ? a/d channel 4. ss st ? slave select input. c2out ? cmos comparator c2 output. ra6/osc2/clkout ra6 ttl cmos general purpose i/o. osc2 ? xtal master clear with internal pull-up. clkout ? cmos f osc /4 output. ra7/osc1/clkin ra7 ttl cmos general purpose i/o. osc1 xtal ? crystal/resonator. clkin st ? external clock input/rc oscillator connection. rb0/an12/int rb0 ttl cmos general purpose i/o. individually controlled interrupt-on-change. individually enabled pull-up. an12 an ? a/d channel 12. int st ? external interrupt. rb1/an10/p1c/c12in3- rb1 ttl cmos general purpose i/o. individually controlled interrupt-on-change. individually enabled pull-up. an10 an ? a/d channel 10. p1c ? cmos pwm output. c12in3- an ? comparator c1 or c2 negative input. rb2/an8/p1b rb2 ttl cmos general purpose i/o. individually controlled interrupt-on-change. individually enabled pull-up. an8 an ? a/d channel 8. p1b ? cmos pwm output. legend: an = analog input or output cmos = cmos compatible input or output od = open drain ttl = ttl compatible input st = schmitt trigger input with cmos levels hv = high voltage xtal = crystal
? 2007 microchip technology inc. preliminary ds41291d-page 17 pic16f882/883/884/886/887 rb3/an9/pgm/c12in2- rb3 ttl cmos general purpose i/o. individually controlled interrupt-on-change. individually enabled pull-up. an9 an ? a/d channel 9. pgm st ? low-voltage icsp? programming enable pin. c12in2- an ? comparator c1 or c2 negative input. rb4/an11/p1d rb4 ttl cmos general purpose i/o. individually controlled interrupt-on-change. individually enabled pull-up. an11 an ? a/d channel 11. p1d ? cmos pwm output. rb5/an13/t1g rb5 ttl cmos general purpose i/o. individually controlled interrupt-on-change. individually enabled pull-up. an13 an ? a/d channel 13. t1g st ? timer1 gate input. rb6/icspclk rb6 ttl cmos general purpose i/o. individually controlled interrupt-on-change. individually enabled pull-up. icspclk st ? serial programming clock. rb7/icspdat rb7 ttl cmos general purpose i/o. individually controlled interrupt-on-change. individually enabled pull-up. icspdat st cmos icsp? data i/o. rc0/t1oso/t1cki rc0 st cmos general purpose i/o. t1oso ? cmos timer1 oscillator output. t1cki st ? timer1 clock input. rc1/t1osi/ccp2 rc1 st cmos general purpose i/o. t1osi st ? timer1 oscillator input. ccp2 st cmos capture/compare/pwm2. rc2/p1a/ccp1 rc2 st cmos general purpose i/o. p1a ? cmos pwm output. ccp1 st cmos capture/compare/pwm1. rc3/sck/scl rc3 st cmos general purpose i/o. sck st cmos spi clock. scl st od i 2 c? clock. rc4/sdi/sda rc4 st cmos general purpose i/o. sdi st ? spi data input. sda st od i 2 c data input/output. rc5/sdo rc5 st cmos general purpose i/o. sdo ? cmos spi data output. rc6/tx/ck rc6 st cmos general purpose i/o. tx ? cmos eusart asynchronous transmit. ck st cmos eusart synchronous clock. rc7/rx/dt rc7 st cmos general purpose i/o. rx st ? eusart asynchronous input. dt st cmos eusart synchronous data. re3/mclr /v pp re3 ttl ? general purpose input. mclr st ? master clear with internal pull-up. v pp hv ? programming voltage. v ss v ss power ? ground reference. v dd v dd power ? positive supply. table 1-1: pic16f882/883/886 pinout description (continued) name function input type output type description legend: an = analog input or output cmos = cmos compatible input or output od = open drain ttl = ttl compatible input st = schmitt trigger input with cmos levels hv = high voltage xtal = crystal
pic16f882/883/884/886/887 ds41291d-page 18 preliminary ? 2007 microchip technology inc. table 1-2: pic16f884/887 pinout description name function input type output type description ra0/an0/ulpwu/c12in0- ra0 ttl cmos general purpose i/o. an0 an ? a/d channel 0 input. ulpwu an ? ultra low-power wake-up input. c12in0- an ? comparator c1 or c2 negative input. ra1/an1/c12in1- ra1 ttl cmos general purpose i/o. an1 an ? a/d channel 1 input. c12in1- an ? comparator c1 or c2 negative input. ra2/an2/v ref -/cv ref /c2in+ ra2 ttl cmos general purpose i/o. an2 an ? a/d channel 2. v ref - an ? a/d negative voltage reference input. cv ref ? an comparator voltage reference output. c2in+ an ? comparator c2 positive input. ra3/an3/v ref +/c1in+ ra3 ttl cmos general purpose i/o. an3 an ? a/d channel 3. v ref + an ? a/d positive voltage reference input. c1in+ an ? comparator c1 positive input. ra4/t0cki/c1out ra4 ttl cmos general purpose i/o. t0cki st ? timer0 clock input. c1out ? cmos comparator c1 output. ra5/an4/ss /c2out ra5 ttl cmos general purpose i/o. an4 an ? a/d channel 4. ss st ? slave select input. c2out ? cmos comparator c2 output. ra6/osc2/clkout ra6 ttl cmos general purpose i/o. osc2 ? xtal crystal/resonator. clkout ? cmos f osc /4 output. ra7/osc1/clkin ra7 ttl cm os general purpose i/o. osc1 xtal ? crystal/resonator. clkin st ? external clock input/rc oscillator connection. rb0/an12/int rb0 ttl cmos general purpose i/o. individually controlled interrupt-on-change. individually enabled pull-up. an12 an ? a/d channel 12. int st ? external interrupt. rb1/an10/c12in3- rb1 ttl cmos general purpose i/o. individually controlled interrupt-on-change. individually enabled pull-up. an10 an ? a/d channel 10. c12in3- an ? comparator c1 or c2 negative input. rb2/an8 rb2 ttl cmos general purpose i/o. i ndividually controlled interrupt-on-change. individually enabled pull-up. an8 an ? a/d channel 8. rb3/an9/pgm/c12in2- rb3 ttl cmos general purpose i/ o. individually controlled interrupt-on-change. individually enabled pull-up. an9 an ? a/d channel 9. pgm st ? low-voltage icsp? programming enable pin. c12in2- an ? comparator c1 or c2 negative input. legend: an = analog input or output cmos = cmos compatible input or output od = open drain ttl = ttl compatible input st = schmitt trigger input with cmos levels hv = high voltage xtal = crystal
? 2007 microchip technology inc. preliminary ds41291d-page 19 pic16f882/883/884/886/887 rb4/an11 rb4 ttl cmos general purpose i/o. i ndividually controlled interrupt-on-change. individually enabled pull-up. an11 an ? a/d channel 11. rb5/an13/t1g rb5 ttl cmos general purpose i/o. indivi dually controlled interrupt-on-change. individually enabled pull-up. an13 an ? a/d channel 13. t1g st ? timer1 gate input. rb6/icspclk rb6 ttl cmos general purpose i/o. individually controlled interrupt-on-change. individually enabled pull-up. icspclk st ? serial programming clock. rb7/icspdat rb7 ttl cmos general purpose i/o. individually controlled interrupt-on-change. individually enabled pull-up. icspdat st ttl icsp? data i/o. rc0/t1oso/t1cki rc0 st cmos general purpose i/o. t1oso ? xtal timer1 oscillator output. t1cki st ? timer1 clock input. rc1/t1osi/ccp2 rc1 st cmos general purpose i/o. t1osi xtal ? timer1 oscillator input. ccp2 st cmos capture/compare/pwm2. rc2/p1a/ccp1 rc2 st cmos general purpose i/o. p1a st cmos pwm output. ccp1 ? cmos capture/compare/pwm1. rc3/sck/scl rc3 st cmos general purpose i/o. sck st cmos spi clock. scl st od i 2 c? clock. rc4/sdi/sda rc4 st cmos general purpose i/o. sdi st ? spi data input. sda st od i 2 c data input/output. rc5/sdo rc5 st cmos general purpose i/o. sdo ? cmos spi data output. rc6/tx/ck rc6 st cmos general purpose i/o. tx ? cmos eusart asynchronous transmit. ck st cmos eusart synchronous clock. rc7/rx/dt rc7 st cmos general purpose i/o. rx st ? eusart asynchronous input. dt st cmos eusart synchronous data. rd0 rd0 ttl cmos general purpose i/o. rd1 rd1 ttl cmos general purpose i/o. rd2 rd2 ttl cmos general purpose i/o. rd3 rd3 ttl cmos general purpose i/o. rd4 rd4 ttl cmos general purpose i/o. rd5/p1b rd5 ttl cmos general purpose i/o. p1b ? cmos pwm output. rd6/p1c rd6 ttl cmos general purpose i/o. p1c ? cmos pwm output. table 1-2: pic16f884/887 pinout description (continued) name function input type output type description legend: an = analog input or output cmos = cmos compatible input or output od = open drain ttl = ttl compatible input st = schmitt trigger input with cmos levels hv = high voltage xtal = crystal
pic16f882/883/884/886/887 ds41291d-page 20 preliminary ? 2007 microchip technology inc. rd7/p1d rd7 ttl cmos general purpose i/o. p1d an ? pwm output. re0/an5 re0 ttl cmos general purpose i/o. an5 an ? a/d channel 5. re1/an6 re1 st cmos general purpose i/o. an6 an ? a/d channel 6. re2/an7 re2 ttl cmos general purpose i/o. an7 an ? a/d channel 7. re3/mclr /v pp re3 ttl ? general purpose input. mclr st ? master clear with internal pull-up. v pp hv ? programming voltage. v ss v ss power ? ground reference. v dd v dd power ? positive supply. table 1-2: pic16f884/887 pinout description (continued) name function input type output type description legend: an = analog input or output cmos = cmos compatible input or output od = open drain ttl = ttl compatible input st = schmitt trigger input with cmos levels hv = high voltage xtal = crystal
? 2007 microchip technology inc. preliminary ds41291d-page 21 pic16f882/883/884/886/887 2.0 memory organization 2.1 program memory organization the pic16f882/883/884/886/887 has a 13-bit program counter capable of addressing a 2k x 14 (0000h-07ffh) for the pic16f882, 4k x 14 (0000h-0fffh) for the pic16f883/pic16f884, and 8k x 14 (0000h-1fffh) for the pic16f886/pic16f887 program memory space. accessing a location above these boundaries will cause a wraparound within the first 8k x 14 space. the reset vector is at 0000h and the interrupt vector is at 0004h (see figures 2-2 and 2-3). figure 2-1: program memory map and stack for the pic16f882 figure 2-2: program memory map and stack for the pic16f883 / pic16f884 figure 2-3: program memory map and stack for the pic16f886 / pic16f887 pc<12:0> 13 0000h 0004h 0005h 07ffh stack level 1 stack level 8 reset vector interrupt vector call, return retfie, retlw stack level 2 page 0 on-chip program memory pc<12:0> 13 0000h 0004h 0005h 07ffh 0800h stack level 1 stack level 8 reset vector interrupt vector call, return retfie, retlw stack level 2 page 0 page 1 0fffh on-chip program memory pc<12:0> 13 0000h 0004h 0005h 07ffh 0800h 17ffh stack level 1 stack level 8 reset vector interrupt vector call, return retfie, retlw stack level 2 page 0 page 1 page 2 page 3 0fffh 1000h 1fffh 1800h on-chip program memory
pic16f882/883/884/886/887 ds41291d-page 22 preliminary ? 2007 microchip technology inc. 2.2 data memory organization the data memory (see figures 2-2 and 2-3) is partitioned into four banks which contain the general purpose registers (gpr) and the special function registers (sfr). the special function registers are located in the first 32 locations of each bank. the general purpose registers, implemented as static ram, are located in the last 96 locations of each bank. register locations f0h-ffh in bank 1, 170h-17fh in bank 2 and 1f0h-1ffh in bank 3, point to addresses 70h-7fh in bank 0. the actual number of general purpose resisters (gpr) implemented in each bank depends on the device. details are shown in figures 2-5 and 2-6. all other ram is unimplemented and returns ? 0 ? when read. rp<1:0> of the status register are the bank select bits: rp1 rp0 00 bank 0 is selected 01 bank 1 is selected 10 bank 2 is selected 11 bank 3 is selected 2.2.1 general purpose register file the register file is organized as 128 x 8 in the pic16f882, 256 x 8 in the pic16f883/pic16f884, and 368 x 8 in the pic16f886/pic16f887. each register is accessed, either directly or indirectly, through the file select register (fsr) (see section 2.4 ?indirect addressing, indf and fsr registers? ). 2.2.2 special function registers the special function registers are registers used by the cpu and peripheral functions for controlling the desired operation of the device (see table 2-1). these registers are static ram. the special registers can be classified into two sets: core and peripheral. the special function registers associated with the ?core? are described in this section. those related to the operation of the peripheral features are described in the section of that peripheral feature. note: the irp and rp1 bits of the status reg- ister are reserved and should always be maintained as ? 0 ?s.
? 2007 microchip technology inc. preliminary ds41291d-page 23 pic16f882/883/884/886/887 figure 2-4: pic16f882 special function registers file file file file address address address address indirect addr. (1) 00h indirect addr. (1) 80h indirect addr. (1) 100h indirect addr. (1) 180h tmr0 01h option_reg 81h tmr0 101h option_reg 181h pcl 02h pcl 82h pcl 102h pcl 182h status 03h status 83h status 103h status 183h fsr 04h fsr 84h fsr 104h fsr 184h porta 05h trisa 85h wdtcon 105h srcon 185h portb 06h trisb 86h portb 106h trisb 186h portc 07h trisc 87h cm1con0 107h baudctl 187h 08h 88h cm2con0 108h ansel 188h porte 09h trise 89h cm2con1 109h anselh 189h pclath 0ah pclath 8ah pclath 10ah pclath 18ah intcon 0bh intcon 8bh intcon 10bh intcon 18bh pir1 0ch pie1 8ch eedat 10ch eecon1 18ch pir2 0dh pie2 8dh eeadr 10dh eecon2 (1) 18dh tmr1l 0eh pcon 8eh eedath 10eh reserved 18eh tmr1h 0fh osccon 8fh eeadrh 10fh reserved 18fh t1con 10h osctune 90h 110h 190h tmr2 11h sspcon2 91h 111h 191h t2con 12h pr2 92h 112h 192h sspbuf 13h sspadd 93h 113h 193h sspcon 14h sspstat 94h 114h 194h ccpr1l 15h wpub 95h 115h 195h ccpr1h 16h iocb 96h 116h 196h ccp1con 17h vrcon 97h 117h 197h rcsta 18h txsta 98h 118h 198h txreg 19h spbrg 99h 119h 199h rcreg 1ah spbrgh 9ah 11ah 19ah ccpr2l 1bh pwm1con 9bh 11bh 19bh ccpr2h 1ch eccpas 9ch 11ch 19ch ccp2con 1dh pstrcon 9dh 11dh 19dh adresh 1eh adresl 9eh 11eh 19eh adcon0 1fh adcon1 9fh 11fh 19fh general purpose registers 96 bytes 20h general purpose registers 32 bytes a0h bfh 120h 1a0h c0h efh 16fh 1efh accesses 70h-7fh f0h accesses 70h-7fh 170h accesses 70h-7fh 1f0h 7fh ffh 17fh 1ffh bank 0 bank 1 bank 2 bank 3 unimplemented data memory locations, read as ? 0 ?. note 1: not a physical register.
pic16f882/883/884/886/887 ds41291d-page 24 preliminary ? 2007 microchip technology inc. figure 2-5: pic16f883 / pic16f884 special function registers file file file file address address address address indirect addr. (1) 00h indirect addr. (1) 80h indirect addr. (1) 100h indirect addr. (1) 180h tmr0 01h option_reg 81h tmr0 101h option_reg 181h pcl 02h pcl 82h pcl 102h pcl 182h status 03h status 83h status 103h status 183h fsr 04h fsr 84h fsr 104h fsr 184h porta 05h trisa 85h wdtcon 105h srcon 185h portb 06h trisb 86h portb 106h trisb 186h portc 07h trisc 87h cm1con0 107h baudctl 187h portd (2) 08h trisd (2) 88h cm2con0 108h ansel 188h porte 09h trise 89h cm2con1 109h anselh 189h pclath 0ah pclath 8ah pclath 10ah pclath 18ah intcon 0bh intcon 8bh intcon 10bh intcon 18bh pir1 0ch pie1 8ch eedat 10ch eecon1 18ch pir2 0dh pie2 8dh eeadr 10dh eecon2 (1) 18dh tmr1l 0eh pcon 8eh eedath 10eh reserved 18eh tmr1h 0fh osccon 8fh eeadrh 10fh reserved 18fh t1con 10h osctune 90h 110h 190h tmr2 11h sspcon2 91h 111h 191h t2con 12h pr2 92h 112h 192h sspbuf 13h sspadd 93h 113h 193h sspcon 14h sspstat 94h 114h 194h ccpr1l 15h wpub 95h 115h 195h ccpr1h 16h iocb 96h 116h 196h ccp1con 17h vrcon 97h 117h 197h rcsta 18h txsta 98h 118h 198h txreg 19h spbrg 99h 119h 199h rcreg 1ah spbrgh 9ah 11ah 19ah ccpr2l 1bh pwm1con 9bh 11bh 19bh ccpr2h 1ch eccpas 9ch 11ch 19ch ccp2con 1dh pstrcon 9dh 11dh 19dh adresh 1eh adresl 9eh 11eh 19eh adcon0 1fh adcon1 9fh 11fh 19fh general purpose registers 96 bytes 20h general purpose registers 80 bytes a0h general purpose registers 80 bytes 120h 1a0h efh 16fh 1efh accesses 70h-7fh f0h accesses 70h-7fh 170h accesses 70h-7fh 1f0h 7fh ffh 17fh 1ffh bank 0bank 1bank 2bank 3 unimplemented data memory locations, read as ? 0 ?. note 1: not a physical register. 2: pic16f884 only.
? 2007 microchip technology inc. preliminary ds41291d-page 25 pic16f882/883/884/886/887 figure 2-6: pic16f886 / pic16f887 special function registers file file file file address address address address indirect addr. (1) 00h indirect addr. (1) 80h indirect addr. (1) 100h indirect addr. (1) 180h tmr0 01h option_reg 81h tmr0 101h option_reg 181h pcl 02h pcl 82h pcl 102h pcl 182h status 03h status 83h status 103h status 183h fsr 04h fsr 84h fsr 104h fsr 184h porta 05h trisa 85h wdtcon 105h srcon 185h portb 06h trisb 86h portb 106h trisb 186h portc 07h trisc 87h cm1con0 107h baudctl 187h portd (2) 08h trisd (2) 88h cm2con0 108h ansel 188h porte 09h trise 89h cm2con1 109h anselh 189h pclath 0ah pclath 8ah pclath 10ah pclath 18ah intcon 0bh intcon 8bh intcon 10bh intcon 18bh pir1 0ch pie1 8ch eedat 10ch eecon1 18ch pir2 0dh pie2 8dh eeadr 10dh eecon2 (1) 18dh tmr1l 0eh pcon 8eh eedath 10eh reserved 18eh tmr1h 0fh osccon 8fh eeadrh 10fh reserved 18fh t1con 10h osctune 90h general purpose registers 16 bytes 110h general purpose registers 16 bytes 190h tmr2 11h sspcon2 91h 111h 191h t2con 12h pr2 92h 112h 192h sspbuf 13h sspadd 93h 113h 193h sspcon 14h sspstat 94h 114h 194h ccpr1l 15h wpub 95h 115h 195h ccpr1h 16h iocb 96h 116h 196h ccp1con 17h vrcon 97h 117h 197h rcsta 18h txsta 98h 118h 198h txreg 19h spbrg 99h 119h 199h rcreg 1ah spbrgh 9ah 11ah 19ah ccpr2l 1bh pwm1con 9bh 11bh 19bh ccpr2h 1ch eccpas 9ch 11ch 19ch ccp2con 1dh pstrcon 9dh 11dh 19dh adresh 1eh adresl 9eh 11eh 19eh adcon0 1fh adcon1 9fh 11fh 19fh general purpose registers 96 bytes 20h 3fh general purpose registers 80 bytes a0h general purpose registers 80 bytes 120h general purpose registers 80 bytes 1a0h 40h 6fh efh 16fh 1efh 70h accesses 70h-7fh f0h accesses 70h-7fh 170h accesses 70h-7fh 1f0h 7fh ffh 17fh 1ffh bank 0bank 1bank 2bank 3 unimplemented data memory locations, read as ? 0 ?. note 1: not a physical register. 2: pic16f887 only.
pic16f882/883/884/886/887 ds41291d-page 26 preliminary ? 2007 microchip technology inc. table 2-1: pic16f882/883/884/886/887 special function registers summary bank 0 addr name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor page bank 0 00h indf addressing this location uses contents of fsr to address data memory (not a physical register) xxxx xxxx 37,213 01h tmr0 timer0 module register xxxx xxxx 73,213 02h pcl program counter?s (pc) least significant byte 0000 0000 37,213 03h status irp rp1 rp0 to pd zdcc 0001 1xxx 29,213 04h fsr indirect data memory address pointer xxxx xxxx 37,213 05h porta (3) ra7 ra6 ra5 ra4 ra3 ra2 ra1 ra0 xxxx xxxx 39,213 06h portb (3) rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 xxxx xxxx 48,213 07h portc (3) rc7 rc6 rc5 rc4 rc3 rc2 rc1 rc0 xxxx xxxx 53,213 08h portd (3,4) rd7 rd6 rd5 rd4 rd3 rd2 rd1 rd0 xxxx xxxx 57,213 09h porte (3) ? ? ? ?re3re2 (4) re1 (4) re0 (4) ---- xxxx 59,213 0ah pclath ? ? ? write buffer for upper 5 bits of program counter ---0 0000 37,213 0bh intcon gie peie t0ie inte rbie t0if intf rbif (1) 0000 000x 31,213 0ch pir1 ? adif rcif txif sspif ccp1if tmr2if tmr1if -000 0000 34,213 0dh pir2 osfif c2if c1if eeif bclif ulpwuif ?ccp2if 0000 00-0 35,213 0eh tmr1l holding register for the least significant byte of the 16-bit tmr1 register xxxx xxxx 76,213 0fh tmr1h holding register for the most significant byte of the 16-bit tmr1 register xxxx xxxx 76,213 10h t1con t1ginv tmr1ge t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on 0000 0000 79,213 11h tmr2 timer2 module register 0000 0000 81,213 12h t2con ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 82,213 13h sspbuf synchronous serial port receive buffer/transmit register xxxx xxxx 179,213 14h sspcon (2) wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 0000 177,213 15h ccpr1l capture/compare/pwm register 1 low byte (lsb) xxxx xxxx 126,213 16h ccpr1h capture/compare/pwm register 1 high byte (msb) xxxx xxxx 126,213 17h ccp1con p1m1 p1m0 dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 0000 0000 124,213 18h rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 159,213 19h txreg eusart transmit data register 0000 0000 151,213 1ah rcreg eusart receive data register 0000 0000 156,213 1bh ccpr2l capture/compare/pwm register 2 low byte (lsb) xxxx xxxx 126,213 1ch ccpr2h capture/compare/pwm register 2 high byte (msb) xxxx xxxx 126,214 1dh ccp2con ? ? dc2b1 dc2b0 ccp2m3 ccp2m2 ccp2m1 ccp2m0 --00 0000 125,214 1eh adresh a/d result register high byte xxxx xxxx 99,214 1fh adcon0 adcs1 adcs0 chs3 chs2 chs1 chs0 go/done adon 0000 0000 104,214 legend: ? = unimplemented locations read as ? 0 ?, u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented note 1: mclr and wdt reset do not affect the previous value data latch. the rbif bit will be cleared upon reset but will set again if the mismatch exists. 2: when sspcon register bits sspm<3:0> = 1001 , any reads or writes to the sspadd sfr address are accessed through the sspmsk register. see registers ? and 13-4 for more detail. 3: port pins with analog functions controlled by the ansel and anselh registers will read ? 0 ? immediately after a reset even though the data latches are either undefined (por) or unchanged (other resets). 4: pic16f884/pic16f887 only.
? 2007 microchip technology inc. preliminary ds41291d-page 27 pic16f882/883/884/886/887 table 2-2: pic16f882/883/884/886/887 special function registers summary bank 1 addr name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor page bank 1 80h indf addressing this location uses contents of fsr to address data memory (not a physical register) xxxx xxxx 37,213 81h option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 30,214 82h pcl program counter?s (pc) least significant byte 0000 0000 37,213 83h status irp rp1 rp0 to pd zdcc 0001 1xxx 29,213 84h fsr indirect data memory address pointer xxxx xxxx 37,213 85h trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 39,214 86h trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 1111 1111 48,214 87h trisc trisc7 trisc6 trisc5 tr isc4 trisc3 trisc2 trisc1 trisc0 1111 1111 53,214 88h trisd (3) trisd7 trisd6 trisd5 trisd4 trisd3 trisd2 trisd1 trisd0 1111 1111 57,214 89h trise ? ? ? ? trise3 trise2 (3) trise1 (3) trise0 (3) ---- 1111 59,214 8ah pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 37,213 8bh intcon gie peie t0ie inte rbie t0if intf rbif (1) 0000 000x 31,213 8ch pie1 ? adie rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 32,214 8dh pie2 osfie c2ie c1ie eeie bclie ulpwuie ? ccp2ie 0000 00-0 33,214 8eh pcon ? ? ulpwue sboren ? ?por bor --01 --qq 36,214 8fh osccon ? ircf2 ircf1 ircf0 osts hts lts scs -110 q000 62,214 90h osctune ? ? ? tun4 tun3 tun2 tun1 tun0 ---0 0000 66,214 91h sspcon2 gcen ackstat ackdt acken rcen pen rsen sen 0000 0000 177,214 92h pr2 timer2 period register 1111 1111 81,214 93h sspadd (2) synchronous serial port (i 2 c mode) address register 0000 0000 185,214 93h sspmsk (2) msk7 msk6 msk5 msk4 msk3 msk2 msk1 msk0 1111 1111 204,214 94h sspstat smp cke d/a psr/w ua bf 0000 0000 185,214 95h wpub wpub7 wpub6 wpub5 wpub4 wpub3 wpub2 wpub1 wpub0 1111 1111 49,214 96h iocb iocb7 iocb6 iocb5 iocb4 iocb3 iocb2 iocb1 iocb0 0000 0000 49,214 97h vrcon vren vroe vrr vrss vr3 vr2 vr1 vr0 0000 0000 97,214 98h txsta csrc tx9 txen sync sendb brgh trmt tx9d 0000 0010 158,214 99h spbrg brg7 brg6 brg5 brg4 brg3 brg2 brg1 brg0 0000 0000 161,214 9ah spbrgh brg15 brg14 brg13 brg12 brg11 brg10 brg9 brg8 0000 0000 161,214 9bh pwm1con prsen pdc6 pdc5 pdc4 pdc3 pdc2 pdc1 pdc0 0000 0000 144,214 9ch eccpas eccpase eccpas2 eccpas1 eccpas0 pssac1 pssac0 pssbd1 pssbd0 0000 0000 141,214 9dh pstrcon ? ? ? strsync strd strc strb stra ---0 0001 145,214 9eh adresl a/d result register low byte xxxx xxxx 99,214 9fh adcon1 adfm ?vcfg1vcfg0 ? ? ? ? 0-00 ---- 105,214 legend: ? = unimplemented locations read as ? 0 ?, u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented note 1: mclr and wdt reset do not affect the previous value data latch. the rbif bit will be cleared upon reset but will set again if the mismatch exists. 2: accessible only when sspcon register bits sspm<3:0> = 1001 . 3: pic16f884/pic16f887 only.
pic16f882/883/884/886/887 ds41291d-page 28 preliminary ? 2007 microchip technology inc. table 2-3: pic16f882/883/884/886/887 special function registers summary bank 2 table 2-4: pic16f882/883/884/886/887 special function registers summary bank 3 addr name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor page bank 2 100h indf addressing this location uses contents of fsr to address data memory (not a physical register) xxxx xxxx 37,213 101h tmr0 timer0 module register xxxx xxxx 73,213 102h pcl program counter?s (pc) least significant byte 0000 0000 37,213 103h status irp rp1 rp0 to pd zdcc 0001 1xxx 29,213 104h fsr indirect data memory address pointer xxxx xxxx 37,213 105h wdtcon ? ? ? wdtps3 wdtps2 wdtps1 wdtps0 swdten ---0 1000 221,214 106h portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 xxxx xxxx 48,213 107h cm1con0 c1on c1out c1oe c1pol ? c1r c1ch1 c1ch0 0000 -000 88,214 108h cm2con0 c2on c2out c2oe c2pol ? c2r c2ch1 c2ch0 0000 -000 89,214 109h cm2con1 mc1out mc2out c1rsel c2rsel ? ? t1gss c2sync 0000 --10 91,215 10ah pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 37,213 10bh intcon gie peie t0ie inte rbie t0if intf rbif (1) 0000 000x 31,213 10ch eedat eedat7 eedat6 eedat5 eedat4 eedat3 eedat2 eedat1 eedat0 0000 0000 112,215 10dh eeadr eeadr7 eeadr6 eeadr5 eeadr4 eeadr3 eeadr2 eeadr1 eeadr0 0000 0000 112,215 10eh eedath ? ? eedath5 eedath4 eedath3 eedath2 eedath1 eedath0 --00 0000 112,215 10fh eeadrh ? ? ? eeadrh4 (2) eeadrh3 eeadrh2 eeadrh1 eeadrh0 ---- 0000 112,215 legend: ? = unimplemented locations read as ? 0 ?, u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented note 1: mclr and wdt reset does not affect the previous value data latch. the rbif bit will be cleared upon reset but will set again if the mismatch exists. 2: pic16f886/pic16f887 only. addrname bit 7bit 6bit 5bit 4bit 3bit 2 bit 1bit 0 value on por, bor page bank 3 180h indf addressing this location uses contents of fsr to address data memory (not a physical register) xxxx xxxx 37,213 181h option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 30,214 182h pcl program counter?s (pc) least significant byte 0000 0000 37,213 183h status irp rp1 rp0 to pd zdcc 0001 1xxx 29,213 184h fsr indirect data memory address pointer xxxx xxxx 37,213 185h srcon sr1 sr0 c1sen c2ren pulss pulsr ? fvren 0000 00-0 93,215 186h trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 1111 1111 48,214 187h baudctl abdovf rcidl ? sckp brg16 ? wue abden 01-0 0-00 160,215 188h ansel ans7 (2) ans6 (2) ans5 (2) ans4 ans3 ans2 ans1 ans0 1111 1111 40,215 189h anselh ? ? ans13 ans12 ans11 ans10 ans9 ans8 --11 1111 99,215 18ah pclath ? ? ? write buffer for the upper 5 bits of the program counter ---0 0000 37,213 18bh intcon gie peie t0ie inte rbie t0if intf rbif (1) 0000 000x 31,213 18ch eecon1 eepgd ? ? ? wrerr wren wr rd x--- x000 113,215 18dh eecon2 eeprom control register 2 (not a physical register) ---- ---- 111,215 legend: ? = unimplemented locations read as ? 0 ?, u = unchanged, x = unknown, q = value depends on condition, shaded = unimplemented note 1: mclr and wdt reset does not affect the previous value data latch. the rbif bit will be cleared upon reset but will set again if the mismatch exists. 2: pic16f884/pic16f887 only.
? 2007 microchip technology inc. preliminary ds41291d-page 29 pic16f882/883/884/886/887 2.2.2.1 status register the status register, shown in register 2-1, contains: ? the arithmetic status of the alu ? the reset status ? the bank select bits for data memory (gpr and sfr) the status register can be the destination for any instruction, like any other register. if the status register is the destination for an instruction that affects the z, dc or c bits, then the write to these three bits is disabled. these bits are set or cleared according to the device logic. furthermore, the to and pd bits are not writable. therefore, the result of an instruction with the status register as destination may be different than intended. for example, clrf status, will clear the upper three bits and set the z bit. this leaves the status register as ?000u u1uu? (where u = unchanged). it is recommended, therefore, that only bcf, bsf, swapf and movwf instructions are used to alter the status register, because these instructions do not affect any status bits. for other instructions not affect- ing any status bits, see section 15.0 ?instruction set summary? note 1: the c and dc bits operate as a borrow and digit borrow out bit, respectively, in subtraction. register 2-1: status: status register r/w-0 r/w-0 r/w-0 r-1 r-1 r/w-x r/w-x r/w-x irp rp1 rp0 to pd zdc (1) c (1) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 irp: register bank select bit (used for indirect addressing) 1 = bank 2, 3 (100h-1ffh) 0 = bank 0, 1 (00h-ffh) bit 6-5 rp<1:0>: register bank select bits (used for direct addressing) 00 = bank 0 (00h-7fh) 01 = bank 1 (80h-ffh) 10 = bank 2 (100h-17fh) 11 = bank 3 (180h-1ffh) bit 4 to : time-out bit 1 = after power-up, clrwdt instruction or sleep instruction 0 = a wdt time-out occurred bit 3 pd : power-down bit 1 = after power-up or by the clrwdt instruction 0 = by execution of the sleep instruction bit 2 z: zero bit 1 = the result of an arithmetic or logic operation is zero 0 = the result of an arithmetic or logic operation is not zero bit 1 dc: digit carry/borrow bit ( addwf , addlw,sublw,subwf instructions) (1) 1 = a carry-out from the 4th low-order bit of the result occurred 0 = no carry-out from the 4th low-order bit of the result bit 0 c: carry/borrow bit ( addwf , addlw, sublw, subwf instructions) (1) 1 = a carry-out from the most significant bit of the result occurred 0 = no carry-out from the most significant bit of the result occurred note 1: for borrow , the polarity is reversed. a subtraction is executed by adding the two?s complement of the second operand. for rotate ( rrf , rlf ) instructions, this bit is loaded with either the high-order or low-order bit of the source register.
pic16f882/883/884/886/887 ds41291d-page 30 preliminary ? 2007 microchip technology inc. 2.2.2.2 option register the option register, shown in register 2-2, is a readable and writable register, which contains various control bits to configure: ? timer0/wdt prescaler ? external int interrupt ?timer0 ? weak pull-ups on portb note: to achieve a 1:1 prescaler assignment for timer0, assign the prescaler to the wdt by setting psa bit of the option register to ? 1 ?. see section 6.3 ?timer1 prescaler? . register 2-2: option_reg: option register r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 rbpu intedg t0cs t0se psa ps2 ps1 ps0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 rbpu : portb pull-up enable bit 1 = portb pull-ups are disabled 0 = portb pull-ups are enabled by individual port latch values bit 6 intedg: interrupt edge select bit 1 = interrupt on rising edge of int pin 0 = interrupt on falling edge of int pin bit 5 t0cs: timer0 clock source select bit 1 = transition on t0cki pin 0 = internal instruction cycle clock (f osc /4) bit 4 t0se: timer0 source edge select bit 1 = increment on high-to-low transition on t0cki pin 0 = increment on low-to-high transition on t0cki pin bit 3 psa: prescaler assignment bit 1 = prescaler is assigned to the wdt 0 = prescaler is assigned to the timer0 module bit 2-0 ps<2:0>: prescaler rate select bits 000 001 010 011 100 101 110 111 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 1 : 256 1 : 1 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 bit value timer0 rate wdt rate
? 2007 microchip technology inc. preliminary ds41291d-page 31 pic16f882/883/884/886/887 2.2.2.3 intcon register the intcon register, shown in register 2-3, is a readable and writable register, which contains the various enable and flag bits for tmr0 register overflow, portb change and external int pin interrupts. note: interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the global enable bit, gie of the intcon register. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. register 2-3: intcon: interrupt control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-x gie peie t0ie inte rbie (1,3) t0if (2) intf rbif bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 gie: global interrupt enable bit 1 = enables all unmasked interrupts 0 = disables all interrupts bit 6 peie: peripheral interrupt enable bit 1 = enables all unmasked peripheral interrupts 0 = disables all peripheral interrupts bit 5 t0ie: timer0 overflow interrupt enable bit 1 = enables the timer0 interrupt 0 = disables the timer0 interrupt bit 4 inte: int external interrupt enable bit 1 = enables the int external interrupt 0 = disables the int external interrupt bit 3 rbie: portb change interrupt enable bit (1,3) 1 = enables the portb change interrupt 0 = disables the portb change interrupt bit 2 t0if: timer0 overflow interrupt flag bit (2) 1 = tmr0 register has overflowed (must be cleared in software) 0 = tmr0 register did not overflow bit 1 intf: int external interrupt flag bit 1 = the int external interrupt occurred (must be cleared in software) 0 = the int external interrupt did not occur bit 0 rbif: portb change interrupt flag bit 1 = when at least one of the portb general purpose i/o pins changed state (must be cleared in software) 0 = none of the portb general purpose i/o pins have changed state note 1: iocb register must also be enabled. 2: t0if bit is set when timer0 rolls over. timer0 is unchanged on reset and should be initialized before clearing t0if bit. 3: includes ulpwu interrupt.
pic16f882/883/884/886/887 ds41291d-page 32 preliminary ? 2007 microchip technology inc. 2.2.2.4 pie1 register the pie1 register contains the interrupt enable bits, as shown in register 2-4. note: bit peie of the intcon register must be set to enable any peripheral interrupt. register 2-4: pie1: peripheral interrupt enable register 1 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? adie rcie txie sspie ccp1ie tmr2ie tmr1ie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 adie: a/d converter (adc) interrupt enable bit 1 = enables the adc interrupt 0 = disables the adc interrupt bit 5 rcie: eusart receive interrupt enable bit 1 = enables the eusart receive interrupt 0 = disables the eusart receive interrupt bit 4 txie: eusart transmit interrupt enable bit 1 = enables the eusart transmit interrupt 0 = disables the eusart transmit interrupt bit 3 sspie: master synchronous serial port (mssp) interrupt enable bit 1 = enables the mssp interrupt 0 = disables the mssp interrupt bit 2 ccp1ie: ccp1 interrupt enable bit 1 = enables the ccp1 interrupt 0 = disables the ccp1 interrupt bit 1 tmr2ie: timer2 to pr2 match interrupt enable bit 1 = enables the timer2 to pr2 match interrupt 0 = disables the timer2 to pr2 match interrupt bit 0 tmr1ie: timer1 overflow interrupt enable bit 1 = enables the timer1 overflow interrupt 0 = disables the timer1 overflow interrupt
? 2007 microchip technology inc. preliminary ds41291d-page 33 pic16f882/883/884/886/887 2.2.2.5 pie2 register the pie2 register contains the interrupt enable bits, as shown in register 2-5. note: bit peie of the intcon register must be set to enable any peripheral interrupt. register 2-5: pie2: peripheral interrupt enable register 2 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 osfie c2ie c1ie eeie bclie ulpwuie ? ccp2ie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 osfie: oscillator fail interrupt enable bit 1 = enables oscillator fail interrupt 0 = disables oscillator fail interrupt bit 6 c2ie: comparator c2 interrupt enable bit 1 = enables comparator c2 interrupt 0 = disables comparator c2 interrupt bit 5 c1ie: comparator c1 interrupt enable bit 1 = enables comparator c1 interrupt 0 = disables comparator c1 interrupt bit 4 eeie: eeprom write operation interrupt enable bit 1 = enables eeprom write operation interrupt 0 = disables eeprom write operation interrupt bit 3 bclie: bus collision interrupt enable bit 1 = enables bus collision interrupt 0 = disables bus collision interrupt bit 2 ulpwuie: ultra low-power wake-up interrupt enable bit 1 = enables ultra low-power wake-up interrupt 0 = disables ultra low-power wake-up interrupt bit 1 unimplemented: read as ? 0 ? bit 0 ccp2ie: ccp2 interrupt enable bit 1 = enables ccp2 interrupt 0 = disables ccp2 interrupt
pic16f882/883/884/886/887 ds41291d-page 34 preliminary ? 2007 microchip technology inc. 2.2.2.6 pir1 register the pir1 register contains the interrupt flag bits, as shown in register 2-6. note: interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the global enable bit, gie of the intcon register. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. register 2-6: pir1: peripheral interrupt request register 1 u-0 r/w-0 r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 ? adif rcif txif sspif ccp1if tmr2if tmr1if bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 adif: a/d converter interrupt flag bit 1 = a/d conversion complete (must be cleared in software) 0 = a/d conversion has not completed or has not been started bit 5 rcif: eusart receive interrupt flag bit 1 = the eusart receive buffer is full (cleared by reading rcreg) 0 = the eusart receive buffer is not full bit 4 txif: eusart transmit interrupt flag bit 1 = the eusart transmit buffer is empty (cleared by writing to txreg) 0 = the eusart transmit buffer is full bit 3 sspif: master synchronous serial port (mssp) interrupt flag bit 1 = the mssp interrupt condition has occurred, and must be cleared in software before returning from the interrupt service routine. the condi tions that will set this bit are: spi a transmission/reception has taken place i 2 c slave/master a transmission/reception has taken place i 2 c master the initiated start condition was completed by the mssp module the initiated stop condition was completed by the mssp module the initiated restart condition was completed by the mssp module the initiated acknowledge condition was completed by the mssp module a start condition occurred while the mssp module was idle (multi-master system) a stop condition occurred while the mssp module was idle (multi-master system) 0 = no mssp interrupt condition has occurred bit 2 ccp1if: ccp1 interrupt flag bit capture mode : 1 = a tmr1 register capture occurred (must be cleared in software) 0 = no tmr1 register capture occurred compare mode : 1 = a tmr1 register compare match occurred (must be cleared in software) 0 = no tmr1 register compare match occurred pwm mode : unused in this mode bit 1 tmr2if: timer2 to pr2 interrupt flag bit 1 = a timer2 to pr2 match occurred (must be cleared in software) 0 = no timer2 to pr2 match occurred bit 0 tmr1if: timer1 overflow interrupt flag bit 1 = the tmr1 register overflowed (must be cleared in software) 0 = the tmr1 register did not overflow
? 2007 microchip technology inc. preliminary ds41291d-page 35 pic16f882/883/884/886/887 2.2.2.7 pir2 register the pir2 register contains the interrupt flag bits, as shown in register 2-7. note: interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the global enable bit, gie of the intcon register. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. register 2-7: pir2: peripheral interrupt request register 2 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 osfif c2if c1if eeif bclif ulpwuif ? ccp2if bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 osfif: oscillator fail interrupt flag bit 1 = system oscillator failed, clock input has changed to intosc (must be cleared in software) 0 = system clock operating bit 6 c2if: comparator c2 interrupt flag bit 1 = comparator output (c2out bit) has changed (must be cleared in software) 0 = comparator output (c2out bit) has not changed bit 5 c1if: comparator c1 interrupt flag bit 1 = comparator output (c1out bit) has changed (must be cleared in software) 0 = comparator output (c1out bit) has not changed bit 4 eeif: ee write operation interrupt flag bit 1 = write operation completed (must be cleared in software) 0 = write operation has not completed or has not started bit 3 bclif: bus collision interrupt flag bit 1 = a bus collision has occurred in the mssp when configured for i 2 c master mode 0 = no bus collision has occurred bit 2 ulpwuif: ultra low-power wake-up interrupt flag bit 1 = wake-up condition has occurred (must be cleared in software) 0 = no wake-up condition has occurred bit 1 unimplemented: read as ? 0 ? bit 0 ccp2if: ccp2 interrupt flag bit capture mode : 1 = a tmr1 register capture occurred (must be cleared in software) 0 = no tmr1 register capture occurred compare mode : 1 = a tmr1 register compare match occurred (must be cleared in software) 0 = no tmr1 register compare match occurred pwm mode : unused in this mode
pic16f882/883/884/886/887 ds41291d-page 36 preliminary ? 2007 microchip technology inc. 2.2.2.8 pcon register the power control (pcon) register (see register 2-8) contains flag bits to differentiate between a: ? power-on reset (por ) ? brown-out reset (bor ) ? watchdog timer reset (wdt) ? external mclr reset the pcon register also controls the ultra low-power wake-up and software enable of the bor . register 2-8: pcon: power control register u-0 u-0 r/w-0 r/w-1 u-0 u-0 r/w-0 r/w-x ? ? ulpwue sboren (1) ? ?por bor bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5 ulpwue: ultra low-power wake-up enable bit 1 = ultra low-power wake-up enabled 0 = ultra low-power wake-up disabled bit 4 sboren: software bor enable bit (1) 1 = bor enabled 0 = bor disabled bit 3-2 unimplemented: read as ? 0 ? bit 1 por : power-on reset status bit 1 = no power-on reset occurred 0 = a power-on reset occurred (must be set in software after a power-on reset occurs) bit 0 bor : brown-out reset status bit 1 = no brown-out reset occurred 0 = a brown-out reset occurred (must be set in software after a brown-out reset occurs) note 1: boren<1:0> = 01 in the configuration word register 1 for this bit to control the bor .
? 2007 microchip technology inc. preliminary ds41291d-page 37 pic16f882/883/884/886/887 2.3 pcl and pclath the program counter (pc) is 13 bits wide. the low byte comes from the pcl register, which is a readable and writable register. the high byte (pc<12:8>) is not directly readable or writable and comes from pclath. on any reset, the pc is cleared. figure 2-7 shows the two situations for the loading of the pc. the upper example in figure 2-7 shows how the pc is loaded on a write to pcl (pclath<4:0> pch). the lower example in figure 2-7 shows how the pc is loaded during a call or goto instruction (pclath<4:3> pch). figure 2-7: loading of pc in different situations 2.3.1 modifying pcl executing any instruction with the pcl register as the destination simultaneously causes the program counter pc<12:8> bits (pch) to be replaced by the contents of the pclath register. this allows the entire contents of the program counter to be changed by writing the desired upper 5 bits to the pclath register. when the lower 8 bits are written to the pcl register, all 13 bits of the program counter will change to the values contained in the pclath register and those being written to the pcl register. a computed goto is accomplished by adding an offset to the program counter ( addwf pcl ). care should be exercised when jumping into a look-up table or program branch table (computed goto ) by modifying the pcl register. assuming that pclath is set to the table start address, if the table length is greater than 255 instructions or if the lower 8 bits of the memory address rolls over from 0xff to 0x00 in the middle of the table, then pclath must be incremented for each address rollover that occurs between the table beginning and the target location within the table. for more information refer to application note an556, ? implementing a table read ? (ds00556). 2.3.2 stack the pic16f882/883/884/886/887 devices have an 8-level x 13-bit wide hardware stack (see figures 2-2 and 2-3). the stack space is not part of either program or data space and the stack pointer is not readable or writable. the pc is pushed onto the stack when a call instruction is executed or an interrupt causes a branch. the stack is poped in the event of a return, retlw or a retfie instruction execution. pclath is not affected by a push or pop operation. the stack operates as a circular buffer. this means that after the stack has been pushed eight times, the ninth push overwrites the value that was stored from the first push. the tenth push overwrites the second push (and so on). 2.4 indirect addressing, indf and fsr registers the indf register is not a physical register. addressing the indf register will cause indirect addressing. indirect addressing is possible by using the indf register. any instruction using the indf register actually accesses data pointed to by the file select register (fsr). reading indf itself indirectly will produce 00h. writing to the indf register indirectly results in a no operation (although status bits may be affected). an effective 9-bit address is obtained by concatenating the 8-bit fsr and the irp bit of the status register, as shown in figure 2-8. a simple program to clear ram location 20h-2fh using indirect addressing is shown in example 2-1. example 2-1: indirect addressing pc 12 8 7 0 5 pclath<4:0> pclath instruction wit h alu result goto , call opcode<10:0> 8 pc 12 11 10 0 11 pclath<4:3> pch pcl 87 2 pclath pch pcl pcl a s destinatio n note 1: there are no status bits to indicate stack overflow or stack underflow conditions. 2: there are no instructions/mnemonics called push or pop. these are actions that occur from the execution of the call, return, retlw and retfie instructions or the vectoring to an interrupt address. movlw 0x20 ;initialize pointer movwf fsr ;to ram next clrf indf ;clear indf register incf fsr ;inc pointer btfss fsr,4 ;all done? goto next ;no clear next continue ;yes continue
pic16f882/883/884/886/887 ds41291d-page 38 preliminary ? 2007 microchip technology inc. figure 2-8: direct/indirect addre ssing pic16f882/883/884/886/887 note: for memory map detail, see figures 2-2 and 2-3. data memory indirect addressing direct addressing bank select location select rp1 rp0 6 0 from opcode irp file select register 7 0 bank select location select 00 01 10 11 180h 1ffh 00h 7fh bank 0 bank 1 bank 2 bank 3
? 2007 microchip technology inc. preliminary ds41291d-page 39 pic16f882/883/884/886/887 3.0 i/o ports there are as many as thirty-five general purpose i/o pins available. depending on which peripherals are enabled, some or all of the pins may not be available as general purpose i/o. in general, when a peripheral is enabled, the associated pin may not be used as a general purpose i/o pin. 3.1 porta and the trisa registers porta is a 8-bit wide, bidirectional port. the corresponding data direction register is trisa (register 3-2). setting a trisa bit (= 1 ) will make the corresponding porta pin an input (i.e., disable the output driver). clearing a trisa bit (= 0 ) will make the corresponding porta pin an output (i.e., enables output driver and puts the contents of the output latch on the selected pin). example 3-1 shows how to initialize porta. reading the porta register (register 3-1) reads the status of the pins, whereas writing to it will write to the port latch. all write operations are read-modify-write operations. therefore, a write to a port implies that the port pins are read, this value is modified and then written to the port data latch. the trisa register (register 3-2) controls the porta pin output drivers, even when they are being used as analog inputs. the user should ensure the bits in the trisa register are maintained set when using them as analog inputs. i/o pins configured as analog input always read ? 0 ?. example 3-1: initializing porta note: the ansel register must be initialized to configure an analog channel as a digital input. pins configured as analog inputs will read ? 0 ?. banksel porta ; clrf porta ;init porta banksel ansel ; clrf ansel ;digital i/o bcf status,rp1 ;bank 1 banksel trisa ; movlw 0ch ;set ra<3:2> as inputs movwf trisa ;and set ra<5:4,1:0> ;as outputs register 3-1: porta: porta register r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ra7 ra6 ra5 ra4 ra3 ra2 ra1 ra0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 ra<7:0> : porta i/o pin bit 1 = port pin is > v ih 0 = port pin is < v il register 3-2: trisa: porta tri-state register r/w-1 (1) r/w-1 (1) r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 trisa<7:0>: porta tri-state control bit 1 = porta pin configured as an input (tri-stated) 0 = porta pin configured as an output note 1: trisa<7:6> always reads ? 1 ? in xt, hs and lp oscillator modes.
pic16f882/883/884/886/887 ds41291d-page 40 preliminary ? 2007 microchip technology inc. 3.2 additional pin functions ra0 also has an ultra low-power wake-up option. the next three sections describe these functions. 3.2.1 ansel register the ansel register (register 3-3) is used to configure the input mode of an i/o pin to analog. setting the appropriate ansel bit high will cause all digital reads on the pin to be read as ? 0 ? and allow analog functions on the pin to operate correctly. the state of the ansel bits has no affect on digital out- put functions. a pin with tris clear and ansel set will still operate as a digital output, but the input mode will be analog. this can cause unexpected behavior when executing read-modify-write instructions on the affected port. register 3-3: ansel: analog select register r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 ans7 (2) ans6 (2) ans5 (2) ans4 ans3 ans2 ans1 ans0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 ans<7:0> : analog select bits analog select between analog or digital function on pins an<7:0>, respectively. 1 = analog input. pin is assigned as analog input (1) . 0 = digital i/o. pin is assigned to port or special function. note 1: setting a pin to an analog input automatically disables the digital input circuitry, weak pull-ups, and interrupt-on-change if available. the corresponding tris bit must be set to input mode in order to allow external control of the voltage on the pin. 2: not implemented on pic16f883/886.
? 2007 microchip technology inc. preliminary ds41291d-page 41 pic16f882/883/884/886/887 3.2.2 ultra low-power wake-up the ultra low-power wake-up (ulpwu) on ra0 allows a slow falling voltage to generate an interrupt-on-change on ra0 without excess current consumption. the mode is selected by setting the ulpwue bit of the pcon register. this enables a small current sink, which can be used to discharge a capacitor on ra0. follow these steps to use this feature: a) charge the capacitor on ra0 by configuring the ra0 pin to output (= 1) . b) configure ra0 as an input. c) enable interrupt-on-change for ra0. d) set the ulpwue bit of the pcon register to begin the capacitor discharge. e) execute a sleep instruction. when the voltage on ra0 drops below v il , an interrupt will be generated which will cause the device to wake-up and execute the next instruction. if the gie bit of the intcon register is set, the device will then call the interrupt vector (0004h). see section 3.4.3 ?inter- rupt-on-change? for more information. this feature provides a low-power technique for periodically waking up the device from sleep. the time-out is dependent on the discharge time of the rc circuit on ra0. see example 3-2 for initializing the ultra low-power wake-up module. a series resistor between ra0 and the external capacitor provides overcurrent protection for the ra0/an0/ulpwu/c12in0- pin and can allow for software calibration of the time-out (see figure 3-1). a timer can be used to measure the charge time and discharge time of the capacitor. the charge time can then be adjusted to provide the desired interrupt delay. this technique will compensate for the affects of temperature, voltage and component accuracy. the ultra low-power wake-up peripheral can also be configured as a simple programmable low voltage detect or temperature sensor. example 3-2: ultra low-power wake-up initialization note: for more information, refer to an879, ? using the microchip ultra low-power wake-up module ? application note (ds00879). banksel porta ; bsf porta,0 ;set ra0 data latch banksel ansel ; bcf ansel,0 ;ra0 to digital i/o banksel trisa ; bcf trisa,0 ;output high to call capdelay ;charge capacitor banksel pir2 ; bcf pir2,ulpwuif ;clear flag bsf pcon,ulpwue ;enable ulp wake-up bsf iocb,0 ;select ra0 ioc bsf trisa,0 ;ra0 to input movlw b?10001000? ;enable interrupt movwf intcon ;and clear flag sleep ;wait for ioc nop ;
pic16f882/883/884/886/887 ds41291d-page 42 preliminary ? 2007 microchip technology inc. 3.2.3 pin descriptions and diagrams each porta pin is multiplexed with other functions. the pins and their combined functions are briefly described here. for specific information about individual functions such as the comparator or the a/d converter (adc), refer to the appropriate section in this data sheet. 3.2.3.1 ra0/an0/ulpwu/c12in0- figure 3-1 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the adc ? a negative analog input to comparator c1 or c2 ? an analog input for the ultra low-power wake-up figure 3-1: block diagram of ra0 i/o pin v dd v ss d q ck q d q ck q rd wr wr rd to comparator analog (1) input mode 01 i ulp data bus porta trisa trisa porta note 1: ansel determines analog input mode. - +v trg ulpwue to a/d converter v ss
? 2007 microchip technology inc. preliminary ds41291d-page 43 pic16f882/883/884/886/887 3.2.3.2 ra1/an1/c12in1- figure 3-2 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the adc ? a negative analog input to comparator c1 or c2 figure 3-2: block diagram of ra1 3.2.3.3 ra2/an2/v ref -/cv ref /c2in+ figure 3-3 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the adc ? a negative voltage reference input for the adc and cv ref ? a comparator voltage reference output ? a positive analog input to comparator c2 figure 3-3: block diagram of ra2 i/o pin v dd v ss d q ck q d q ck q analog (1) input mode data bus rd porta wr porta wr trisa rd trisa to a/d converter note 1: ansel determines analog input mode. to comparator i/o pin v dd v ss d q ck q d q ck q analog (1) input mode data bus rd porta wr porta wr trisa rd trisa to comparator (v ref -) note 1: ansel determines analog input mode. to comparator (positive input) cv ref vroe to a/d converter (v ref -) to a/d converter (analog channel)
pic16f882/883/884/886/887 ds41291d-page 44 preliminary ? 2007 microchip technology inc. 3.2.3.4 ra3/an3/v ref +/c1in+ figure 3-4 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose input ? an analog input for the adc ? a positive voltage reference input for the adc and cv ref ? a positive analog input to comparator c1 figure 3-4: block diagram of ra3 3.2.3.5 ra4/t0cki/c1out figure 3-5 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? a clock input for timer0 ? a digital output from comparator c1 figure 3-5: block diagram of ra4 i/o pin v dd v ss d q ck q d q ck q analog (1) input mode data bus rd porta wr porta wr trisa rd trisa note 1: ansel determines analog input mode. to comparator (v ref +) to comparator (positive input) to a/d converter (v ref +) to a/d converter (analog channel) i/o pin v dd v ss d q ck q d q ck q data bus rd porta wr porta wr trisa rd trisa 0 1 c1out c1out enable to ti m e r 0
? 2007 microchip technology inc. preliminary ds41291d-page 45 pic16f882/883/884/886/887 3.2.3.6 ra5/an4/ss /c2out figure 3-6 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the adc ? a slave select input ? a digital output from comparator c2 figure 3-6: block diagram of ra5 3.2.3.7 ra6/osc2/clkout figure 3-7 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? a crystal/resonator connection ? a clock output figure 3-7: block diagram of ra6 i/o pin v dd v ss d q ck q d q ck q analog (1) input mode data bus rd porta wr porta wr trisa rd trisa 0 1 c2out c2out enable to s s input to a/d converter note 1: ansel determines analog input mode. i/o pin v dd v ss d q ck q d q ck q data bus rd porta wr porta wr trisa rd trisa f osc /4 osc2 clkout 0 1 clkout enable enable intoscio/ extrcio/ec (1) clkout enable note 1: with i/o option. circuit oscillator
pic16f882/883/884/886/887 ds41291d-page 46 preliminary ? 2007 microchip technology inc. 3.2.3.8 ra7/osc1/clkin figure 3-8 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? a crystal/resonator connection ? a clock input figure 3-8: block diagram of ra7 table 3-1: summary of registers associated with porta i/o pin v dd v ss d q ck q d q ck q data bus rd porta wr porta wr trisa rd trisa intosc mode osc1 clkin circuit oscillator name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets adcon0 adcs1 adcs0 chs3 chs2 chs1 chs0 go/done adon 0000 0000 0000 0000 ansel ans7 ans6 ans5 ans4 ans3 ans2 ans1 ans0 1111 1111 1111 1111 cm1con0 c1on c1out c1oe c1pol ? c1r c1ch1 c1ch0 0000 -000 0000 -000 cm2con0 c2on c2out c2oe c2pol ? c2r c2ch1 c2ch0 0000 -000 0000 -000 cm2con1 mc1out mc2out c1rsel c2rsel ? ? t1gss c2sync 0000 --10 0000 --10 pcon ? ? ulpwue sboren ? ?por bor --01 --qq --0u --uu option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 porta ra7 ra6 ra5 ra4 ra3 ra2 ra1 ra0 xxxx xxxx uuuu uuuu sspcon wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 0000 0000 0000 trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 1111 1111 legend: x = unknown, u = unchanged, ? = unimplemented locations read as ? 0 ?. shaded cells are not used by porta.
? 2007 microchip technology inc. preliminary ds41291d-page 47 pic16f882/883/884/886/887 3.3 portb and trisb registers portb is an 8-bit wide, bidirectional port. the corresponding data direction register is trisb (register 3-6). setting a trisb bit (= 1 ) will make the corresponding portb pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisb bit (= 0 ) will make the corresponding portb pin an output (i.e., enable the output driver and put the contents of the output latch on the selected pin). example 3-3 shows how to initialize portb. reading the portb register (register 3-5) reads the status of the pins, whereas writing to it will write to the port latch. all write operations are read-modify-write operations. therefore, a write to a port implies that the port pins are read, this value is modified and then written to the port data latch. the trisb register (register 3-6) controls the portb pin output drivers, even when they are being used as analog inputs. the user should ensure the bits in the trisb register are maintained set when using them as analog inputs. i/o pins configured as analog input always read ? 0 ?. example 3-3 shows how to initialize portb. example 3-3: initializing portb 3.4 additional portb pin functions portb pins rb<7:0> on the device family device have an interrupt-on-change option and a weak pull-up option. the following three sections describe these portb pin functions. every portb pin on this device family has an interrupt-on-change option and a weak pull-up option. 3.4.1 anselh register the anselh register (register 3-4) is used to configure the input mode of an i/o pin to analog. setting the appropriate anselh bit high will cause all digital reads on the pin to be read as ? 0 ? and allow analog functions on the pin to operate correctly. the state of the anselh bits has no affect on digital output functions. a pin with tris clear and anselh set will still operate as a digital output, but the input mode will be analog. this can cause unexpected behavior when executing read-modify-write instructions on the affected port. 3.4.2 weak pull-ups each of the portb pins has an individually configurable internal weak pull-up. control bits wpub<7:0> enable or disable each pull-up (see register 3-7). each weak pull-up is automatically turned off when the port pin is configured as an output. all pull-ups are disabled on a power-on reset by the rbpu bit of the option register. 3.4.3 interrupt-on-change all of the portb pins are individually configurable as an interrupt-on-change pin. control bits iocb<7:0> enable or disable the interrupt function for each pin. refer to register 3-8. the interr upt-on-change feature is disabled on a power-on reset. for enabled interrupt-on-change pins, the present value is compared with the old value latched on the last read of portb to determine which bits have changed or mismatched the old value. the ?mismatch? outputs of the last read are or?d together to set the portb change interrupt flag bit (rbif) in the intcon register. this interrupt can wake the device from sleep. the user, in the interrupt service routine, clears the interrupt by: a) any read or write of portb. this will end the mismatch condition. b) clear the flag bit rbif. a mismatch condition will continue to set flag bit rbif. reading or writing portb will end the mismatch condition and allow flag bit rbif to be cleared. the latch holding the last read value is not affected by a mclr nor brown-out reset. after these resets, the rbif flag will continue to be set if a mismatch is present. note: the anselh register must be initialized to configure an analog channel as a digital input. pins configured as analog inputs will read ? 0 ?. banksel portb ; clrf portb ;init portb banksel trisb ; movlw b?11110000? ;set rb<7:4> as inputs ;and rb<3:0> as outputs movwf trisb ; note: if a change on the i/o pin should occur when the read operation is being executed (start of the q2 cycle), then the rbif interrupt flag may not get set. furthermore, since a read or write on a port affects all bits of that port, care must be taken when using multiple pins in interrupt-on-change mode. changes on one pin may not be seen while servicing changes on another pin.
pic16f882/883/884/886/887 ds41291d-page 48 preliminary ? 2007 microchip technology inc. register 3-4: anselh: analog select high register u-0 u-0 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 ? ? ans13 ans12 ans11 ans10 ans9 ans8 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-0 ans<13:8> : analog select bits analog select between analog or digital function on pins an<13:8>, respectively. 1 = analog input. pin is assigned as analog input (1) . 0 = digital i/o. pin is assigned to port or special function. note 1: setting a pin to an analog input automatically disables the digital input circuitry, weak pull-ups, and interrupt-on-change if available. the corresponding tris bit must be set to input mode in order to allow external control of the voltage on the pin. register 3-5: portb: portb register r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 rb<7:0> : portb i/o pin bit 1 = port pin is > v ih 0 = port pin is < v il register 3-6: trisb: portb tri-state register r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 trisb<7:0>: portb tri-state control bit 1 = portb pin configured as an input (tri-stated) 0 = portb pin configured as an output
? 2007 microchip technology inc. preliminary ds41291d-page 49 pic16f882/883/884/886/887 register 3-7: wpub: weak pull-up portb register r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 wpub7 wpub6 wpub5 wpub4 wpub3 wpub2 wpub1 wpub0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 wpub<7:0> : weak pull-up register bit 1 = pull-up enabled 0 = pull-up disabled note 1: global rbpu bit of the option register must be cleared for individual pull-ups to be enabled. 2: the weak pull-up device is automatically disabled if the pin is in configured as an output. register 3-8: iocb: interrupt-on-change portb register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 iocb7 iocb6 iocb5 iocb4 iocb3 iocb2 iocb1 iocb0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 iocb<7:0>: interrupt-on-change portb control bit 1 = interrupt-on-change enabled 0 = interrupt-on-change disabled
pic16f882/883/884/886/887 ds41291d-page 50 preliminary ? 2007 microchip technology inc. 3.4.4 pin descriptions and diagrams each portb pin is multiplexed with other functions. the pins and their combined functions are briefly described here. for specific information about individual functions such as the ssp, i 2 c or interrupts, refer to the appropriate section in this data sheet. 3.4.4.1 rb0/an12/int figure 3-9 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the adc ? an external edge triggered interrupt 3.4.4.2 rb1/an10/p1c (1) /c12in3- figure 3-9 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the adc ? a pwm output (1) ? an analog input to comparator c1 or c2 3.4.4.3 rb2/an8/p1b (1) figure 3-9 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the adc ? a pwm output (1) 3.4.4.4 rb3/an9/pgm/c12in2- figure 3-9 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the adc ? low-voltage in-circuit serial programming enable pin ? an analog input to comparator c1 or c2 figure 3-9: block diagram of rb<3:0> note 1: p1c is available on pic16f882/883/886 only. note 1: p1b is available on pic16f882/883/886 only. i/o pin v dd v ss d q ck q d q ck q d q ck q v dd weak analog (1) input mode data bus wr wpub rd wpub wr portb wr trisb rd trisb to a/d converter rb0/int analog (1) input mode rbp u note 1: anselh determines analog input mode. rb3/pgm to comparator (rb1, rb3) d q ck q d en q d en q rd portb rd portb wr iocb rd iocb interrupt-on- change q3 1 0 ccp1out enable ccp1out
? 2007 microchip technology inc. preliminary ds41291d-page 51 pic16f882/883/884/886/887 3.4.4.5 rb4/an11/p1d (1) figure 3-10 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the adc ? a pwm output (1) 3.4.4.6 rb5/an13/t1g figure 3-10 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the adc ? a timer1 gate input 3.4.4.7 rb6/icspclk figure 3-10 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? in-circuit serial programming clock 3.4.4.8 rb7/icspdat figure 3-10 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? in-circuit serial programming data figure 3-10: block diagram of rb<7:4> note 1: p1d is available on pic16f882/883/886 only. i/o pin v dd v ss d q ck q d q ck q d q ck q d q ck q v dd d en q d en q weak data bus wr wpub rd wpub rd portb rd portb wr portb wr trisb rd trisb wr iocb rd iocb interrupt-on- analog (1) input mode rbpu change q3 available on pic16f882/pic16f883/pic16f886 only. note 1: anselh determines analog input mode. 2: applies to rb<7:6> pins only). 3: applies to rb5 pin only. to a/d converter 1 0 ccp1out enable ccp1out 0 1 1 0 analog (1) input mode to timer1 t1g (3) icsp? (2) to icspclk (rb6) and icspdat (rb7)
pic16f882/883/884/886/887 ds41291d-page 52 preliminary ? 2007 microchip technology inc. table 3-2: summary of registers associated with portb name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets anselh ? ? ans13 ans12 ans11 ans10 ans9 ans8 --11 1111 --11 1111 ccp1con p1m1 p1m0 dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 0000 0000 0000 0000 cm2con1 mc1out mc2out c1rsel c2rsel ? ?t1gss c2sync 0000 --10 0000 --10 iocb iocb7 iocb6 iocb5 ioc b4 iocb3 iocb2 iocb1 iocb0 0000 0000 0000 0000 intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 xxxx xxxx uuuu uuuu trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 1111 1111 1111 1111 wpub wpub7 wpub6 wpub5 wpub4 wpub3 wpub2 wpub1 wpub0 1111 1111 1111 1111 legend: x = unknown, u = unchanged, ? = unimplemented read as ? 0 ?. shaded cells are not used by portb.
? 2007 microchip technology inc. preliminary ds41291d-page 53 pic16f882/883/884/886/887 3.5 portc and trisc registers portc is a 8-bit wide, bidirectional port. the corresponding data direction register is trisc (register 3-10). setting a trisc bit (= 1 ) will make the corresponding portc pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisc bit (= 0 ) will make the corresponding portc pin an output (i.e., enable the output driver and put the contents of the output latch on the selected pin). example 3-4 shows how to initialize portc. reading the portc register (register 3-9) reads the status of the pins, whereas writing to it will write to the port latch. all write operations are read-modify-write operations. therefore, a write to a port implies that the port pins are read, this value is modified and then written to the port data latch. the trisc register (register 3-10) controls the portc pin output drivers, even when they are being used as analog inputs. the user should ensure the bits in the trisc register are maintained set when using them as analog inputs. i/o pins configured as analog input always read ? 0 ?. example 3-4: initializing portc banksel portc ; clrf portc ;init portc banksel trisc ; movlw b?00001100? ;set rc<3:2> as inputs movwf trisc ;and set rc<7:4,1:0> ;as outputs register 3-9: portc: portc register r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x rc7 rc6 rc5 rc4 rc3 rc2 rc1 rc0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 rc<7:0> : portc general purpose i/o pin bit 1 = port pin is > v ih 0 = port pin is < v il register 3-10: trisc: portc tri-state register r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 (1) r/w-1 (1) trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 trisc<7:0>: portc tri-state control bit 1 = portc pin configured as an input (tri-stated) 0 = portc pin configured as an output note 1: trisc<1:0> always reads ? 1 ? in lp oscillator mode.
pic16f882/883/884/886/887 ds41291d-page 54 preliminary ? 2007 microchip technology inc. 3.5.1 rc0/t1oso/t1cki figure 3-11 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? a timer1 oscillator output ? a timer1 clock input figure 3-11: block diagram of rc0 3.5.2 rc1/t1osi/ccp2 figure 3-12 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? a timer1 oscillator input ? a capture input and compare/pwm output for comparator c2 figure 3-12: block diagram of rc1 3.5.3 rc2/p1a/ccp1 figure 3-13 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? a pwm output ? a capture input and compare output for comparator c1 figure 3-13: block diagram of rc2 i/o pin v dd v ss d q ck q d q ck q data bus rd portc wr portc wr trisc rd trisc to timer1 clock input t1oscen circuit timer1 oscillator i/o pin v dd v ss d q ck q d q ck q data bus rd portc wr portc wr trisc rd trisc to ccp2 ccp2 ccp2con 0 1 1 0 t1oscen t1oscen circuit timer1 oscillator t1osi v dd v ss d q ck q d q ck q data bus wr portc wr trisc rd trisc to enhanced ccp1 rd portc ccp1/p1a ccp1con 0 1 1 0 i/o pi n
? 2007 microchip technology inc. preliminary ds41291d-page 55 pic16f882/883/884/886/887 3.5.4 rc3/sck/scl figure 3-14 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? a spi clock ?an i 2 c? clock figure 3-14: block diagram of rc3 3.5.5 rc4/sdi/sda figure 3-15 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? a spi data i/o ?an i 2 c data i/o figure 3-15: block diagram of rc4 3.5.6 rc5/sdo figure 3-16 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? a serial data output figure 3-16: block diagram of rc5 i/o pin v dd v ss d q ck q d q ck q data bus rd portc wr portc wr trisc rd trisc to sspsr sspen 0 1 1 0 sck i/o pin v dd v ss d q ck q d q ck q data bus rd portc wr portc wr trisc rd trisc to sspsr sspen 0 1 1 0 sdi/sda i/o pin v dd v ss d q ck q d q ck q data bus rd portc wr portc wr trisc rd trisc port/sdo 0 1 1 0 sdo select
pic16f882/883/884/886/887 ds41291d-page 56 preliminary ? 2007 microchip technology inc. 3.5.7 rc6/tx/ck figure 3-17 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? an asynchronous serial output ? a synchronous clock i/o figure 3-17: block diagram of rc6 3.5.8 rc7/rx/dt figure 3-18 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? an asynchronous serial input ? a synchronous serial data i/o figure 3-18: block diagram of rc7 table 3-3: summary of registers associated with portc i/o pin v dd v ss d q ck q d q ck q data bus rd portc wr portc wr trisc rd trisc spen txen ck tx sync eusart eusart 0 1 1 0 0 1 1 0 i/o pin v dd v ss d q ck q d q ck q data bus rd portc wr portc wr trisc rd trisc spen sync eusart 0 1 1 0 dt eusart rx/dt name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets ccp1con p1m1 p1m0 dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 0000 0000 0000 0000 ccp2con ? ? dc2b1 dc2b0 ccp2m3 ccp2m2 ccp2m1 ccp2m0 --00 0000 --00 0000 portc rc7 rc6 rc5 rc4 rc3 rc2 rc1 rc0 xxxx xxxx uuuu uuuu pstrcon ? ? ? strsync strd strc strb stra ---0 0001 ---0 0001 rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x sspcon wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 0000 0000 0000 t1con t1ginv tmr1ge t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on 0000 0000 0000 0000 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 1111 1111 1111 1111 legend: x = unknown, u = unchanged, ? = unimplemented locations read as ? 0 ?. shaded cells are not used by portc.
? 2007 microchip technology inc. preliminary ds41291d-page 57 pic16f882/883/884/886/887 3.6 portd and trisd registers portd (1) is a 8-bit wide, bidirectional port. the corresponding data direction register is trisd (register 3-12). setting a trisd bit (= 1 ) will make the corresponding portd pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisd bit (= 0 ) will make the corresponding portd pin an output (i.e., enable the output driver and put the contents of the output latch on the selected pin). example 3-5 shows how to initialize portd. reading the portd register (register 3-11) reads the status of the pins, whereas writing to it will write to the port latch. all write operations are read-modify-write operations. therefore, a write to a port implies that the port pins are read, this value is modified and then written to the port data latch. the trisd register (register 3-12) controls the portd pin output drivers, even when they are being used as analog inputs. the user should ensure the bits in the trisd register are maintained set when using them as analog inputs. i/o pins configured as analog input always read ? 0 ?. example 3-5: initializing portd note 1: portd is available on pic16f884/887 only. banksel portd ; clrf portd ;init portd banksel trisd ; movlw b?00001100? ;set rd<3:2> as inputs movwf trisd ;and set rd<7:4,1:0> ;as outputs register 3-11: portd: portd register r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x rd7 rd6 rd5 rd4 rd3 rd2 rd1 rd0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 rd<7:0> : portd general purpose i/o pin bit 1 = port pin is > v ih 0 = port pin is < v il register 3-12: trisd: portd tri-state register r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 trisd7 trisd6 trisd5 trisd4 trisd3 trisd2 trisd1 trisd0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 trisd<7:0>: portd tri-state control bit 1 = portd pin configured as an input (tri-stated) 0 = portd pin configured as an output
pic16f882/883/884/886/887 ds41291d-page 58 preliminary ? 2007 microchip technology inc. 3.6.1 rd<4:0> figure 3-19 shows the diagram for these pins. these pins are configured to function as general purpose i/o?s. figure 3-19: block diagram of rd<4:0> 3.6.2 rd5/p1b (1) figure 3-20 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? a pwm output 3.6.3 rd6/p1c (1) figure 3-20 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? a pwm output 3.6.4 rd7/p1d (1) figure 3-20 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose i/o ? a pwm output figure 3-20: block diagram of rd<7:5> table 3-4: summary of registers associated with portd note: rd<4:0> is available on pic16f884/887 only. note 1: rd5/p1b is available on pic16f884/887 only. see rb2/ an8/p1b for this function on pic16f882/883/886. v dd v ss d q ck q d q ck q data bus wr portd wr trisd rd trisd rd portd i/o pin note 1: rd6/p1c is available on pic16f884/887 only. see rb1/an10/p1c/c12in3- for this function on pic16f882/883/886. note 1: rd7/p1d is available on pic16f884/887 only. see rb4/an11/p1d for this function on pic16f882/883/886. v dd v ss d q ck q d q ck q data bus wr portd wr trisd rd trisd rd portd ccp1 pstrcon 0 1 1 0 i/o pin name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets portd rd7 rd6 rd5 rd4 rd3 rd2 rd1 rd0 xxxx xxxx uuuu uuuu pstrcon ? ? ? strsync strd strc strb stra ---0 0001 ---0 0001 trisd trisd7 trisd6 trisd5 trisd4 trisd3 trisd2 trisd1 trisd0 1111 1111 1111 1111 legend: x = unknown, u = unchanged, ? = unimplemented locations read as ? 0 ?. shaded cells are not used by portd.
? 2007 microchip technology inc. preliminary ds41291d-page 59 pic16f882/883/884/886/887 3.7 porte and trise registers porte (1) is a 4-bit wide, bidirectional port. the corresponding data direction register is trise. setting a trise bit (= 1 ) will make the corresponding porte pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trise bit (= 0 ) will make the corresponding porte pin an output (i.e., enable the output driver and put the contents of the output latch on the selected pin). the exception is re3, which is input only and its tris bit will always read as ? 1 ?. example 3-6 shows how to initialize porte. reading the porte register (register 3-13) reads the status of the pins, whereas writing to it will write to the port latch. all write operations are read-modify-write operations. therefore, a write to a port implies that the port pins are read, this value is modified and then written to the port data latch. re3 reads ? 0 ? when mclre = 1. the trise register (register 3-14) controls the porte pin output drivers, even when they are being used as analog inputs. the user should ensure the bits in the trise register are maintained set when using them as analog inputs. i/o pins configured as analog input always read ? 0 ?. example 3-6: initializing porte note 1: re<2:0> pins are available on pic16f884/887 only. note: the ansel register must be initialized to configure an analog channel as a digital input. pins configured as analog inputs will read ? 0 ?. banksel porte ; clrf porte ;init porte banksel ansel ; clrf ansel ;digital i/o bcf status,rp1 ;bank 1 banksel trise ; movlw b?00001100? ;set re<3:2> as inputs movwf trise ;and set re<1:0> ;as outputs register 3-13: porte: porte register u-0 u-0 u-0 u-0 r-x r/w-x r/w-x r/w-x ? ? ? ? re3 re2 re1 re0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 unimplemented : read as ? 0 ? bit 3-0 rd<3:0> : porte general purpose i/o pin bit 1 = port pin is > v ih 0 = port pin is < v il register 3-14: trise: porte tri-state register u-0 u-0 u-0 u-0 r-1 (1) r/w-1 r/w-1 r/w-1 ? ? ? ? trise3 trise2 trise1 trise0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 unimplemented : read as ? 0 ? bit 3-0 trise<3:0>: porte tri-state control bit 1 = porte pin configured as an input (tri-stated) 0 = porte pin configured as an output note 1: trise<3> always reads ? 1 ?.
pic16f882/883/884/886/887 ds41291d-page 60 preliminary ? 2007 microchip technology inc. 3.7.1 re0/an5 (1) this pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the adc 3.7.2 re1/an6 (1) this pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the adc 3.7.3 re2/an7 (1) this pin is configurable to function as one of the following: ? a general purpose i/o ? an analog input for the adc figure 3-21: block diagram of re<2:0> 3.7.4 re3/mclr /v pp figure 3-22 shows the diagram for this pin. this pin is configurable to function as one of the following: ? a general purpose input ? as master clear reset with weak pull-up figure 3-22: block diagram of re3 table 3-5: summary of registers associated with porte note 1: re0/an5 is available on pic16f884/887 only. note 1: re1/an6 is available on pic16f884/887 only. note 1: re2/an7 is available on pic16f884/887 only. i/o pin v dd v ss d q ck q d q ck q analog (1) input mode data bus rd porte wr porte wr trise rd trise to a/d converter note 1: ansel determines analog input mode. input v ss data bus rd porte reset mclre rd trise v ss mclre v dd weak mclre pin name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets ansel ans7 ans6 ans5 ans4 ans3 ans2 ans1 ans0 1111 1111 1111 1111 porte ? ? ? ? re3 re2 re1 re0 ---- xxxx ---- uuuu trise ? ? ? ? trise3 trise2 trise1 trise0 ---- 1111 ---- 1111 legend: x = unknown, u = unchanged, ? = unimplemented locations read as ? 0 ?. shaded cells are not used by porte
? 2007 microchip technology inc. preliminary 41291d-page 61 pic16f882/883/884/886/887 4.0 oscillator module (with fail-safe clock monitor) 4.1 overview the oscillator module has a wide variety of clock sources and selection features that allow it to be used in a wide range of applications while maximizing perfor- mance and minimizing power consumption. figure 4-1 illustrates a block diagram of the oscillator module. clock sources can be configured from external oscillators, quartz crystal resonators, ceramic resonators and resistor-capacitor (rc) circuits. in addition, the system clock source can be configured from one of two internal oscillators, with a choice of speeds selectable via software. additional clock features include: ? selectable system clock source between external or internal via software. ? two-speed start-up mode, which minimizes latency between external oscillator start-up and code execution. ? fail-safe clock monitor (fscm) designed to detect a failure of the external clock source (lp, xt, hs, ec or rc modes) and switch automatically to the internal oscillator. the oscillator module can be configured in one of eight clock modes. 1. ec ? external clock with i/o on osc2/clkout. 2. lp ? 32 khz low-power crystal mode. 3. xt ? medium gain crystal or ceramic resonator oscillator mode. 4. hs ? high gain crystal or ceramic resonator mode. 5. rc ? external resistor-capacitor (rc) with f osc /4 output on osc2/clkout. 6. rcio ? external resistor-capacitor (rc) with i/o on osc2/clkout. 7. intosc ? internal oscillator with f osc /4 output on osc2 and i/o on osc1/clkin. 8. intoscio ? internal oscillator with i/o on osc1/clkin and osc2/clkout. clock source modes are configured by the fosc<2:0> bits in the configuration word register 1 (config1). the internal clock can be generated from two internal oscillators. the hfintosc is a calibrated high-frequency oscillator. the lfintosc is an uncalibrated low-frequency oscillator. figure 4-1: pic ? mcu clock source block diagram (cpu and peripherals) osc1 osc2 sleep external oscillator lp, xt, hs, rc, rcio, ec system clock postscaler mux mux 8 mhz 4 mhz 2 mhz 1 mhz 500 khz 125 khz 250 khz ircf<2:0> 111 110 101 100 011 010 001 000 31 khz power-up timer (pwrt) fosc<2:0> (configuration word register 1) scs<0> (osccon register) internal oscillator (osccon register) watchdog timer (wdt) fail-safe clock monitor (fscm) hfintosc 8 mhz lfintosc 31 khz intosc
pic16f882/883/884/886/887 41291d-page 62 preliminary ? 2007 microchip technology inc. 4.2 oscillator control the oscillator control (osccon) register (figure 4-1) controls the system clock and frequency selection options. the osccon register contains the following bits: ? frequency selection bits (ircf) ? frequency status bits (hts, lts) ? system clock control bits (osts, scs) register 4-1: osccon: oscillator control register u-0 r/w-1 r/w-1 r/w-0 r-1 r-0 r-0 r/w-0 ? ircf2 ircf1 ircf0 osts (1) hts lts scs bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-4 ircf<2:0>: internal oscillator frequency select bits 111 = 8 mhz 110 = 4 mhz (default) 101 = 2 mhz 100 = 1 mhz 011 = 500 khz 010 = 250 khz 001 = 125 khz 000 = 31 khz (lfintosc) bit 3 osts: oscillator start-up time-out status bit (1) 1 = device is running from the external clock defined by fosc<2:0> of the config1 register 0 = device is running from the internal oscillator (hfintosc or lfintosc) bit 2 hts: hfintosc status bit (high frequency ? 8 mhz to 125 khz) 1 = hfintosc is stable 0 = hfintosc is not stable bit 1 lts: lfintosc stable bit (low frequency ? 31 khz) 1 = lfintosc is stable 0 = lfintosc is not stable bit 0 scs: system clock select bit 1 = internal oscillator is used for system clock 0 = clock source defined by fosc<2:0> of the config1 register note 1: bit resets to ? 0 ? with two-speed start-up and lp, xt or hs selected as the oscillator mode or fail-safe mode is enabled.
? 2007 microchip technology inc. preliminary 41291d-page 63 pic16f882/883/884/886/887 4.3 clock source modes clock source modes can be classified as external or internal. ? external clock modes rely on external circuitry for the clock source. examples are: oscillator mod- ules (ec mode), quartz crystal resonators or ceramic resonators (lp, xt and hs modes) and resistor-capacitor (rc) mode circuits. ? internal clock sources are contained internally within the oscillator module. the oscillator module has two internal oscillators: the 8 mhz high-frequency internal oscillator (hfintosc) and the 31 khz low-frequency internal oscillator (lfintosc). the system clock can be selected between external or internal clock sources via the system clock select (scs) bit of the osccon register. see section 4.6 ?clock switching? for additional information. 4.4 external clock modes 4.4.1 oscillator start-up timer (ost) if the oscillator module is configured for lp, xt or hs modes, the oscillator start-up timer (ost) counts 1024 oscillations from osc1. this occurs following a power-on reset (por) and when the power-up timer (pwrt) has expired (if configured), or a wake-up from sleep. during this time, the program counter does not increment and program execution is suspended. the ost ensures that the oscillator circuit, using a quartz crystal resonator or ceramic resonator, has started and is providing a stable system clock to the oscillator module. when switching between clock sources, a delay is required to allow the new clock to stabilize. these oscillator delays are shown in table 4-1. in order to minimize latency between external oscillator start-up and code execution, the two-speed clock start-up mode can be selected (see section 4.7 ?two-speed clock start-up mode? ). table 4-1: oscillator delay examples 4.4.2 ec mode the external clock (ec) mode allows an externally generated logic level as the system clock source. when operating in this mode, an external clock source is connected to the osc1 input and the osc2 is available for general purpose i/o. figure 4-2 shows the pin connections for ec mode. the oscillator start-up timer (ost) is disabled when ec mode is selected. therefore, there is no delay in operation after a power-on reset (por) or wake-up from sleep. because the pic ? mcu design is fully static, stopping the external clock input will have the effect of halting the device while leaving all data intact. upon restarting the external clock, the device will resume operation as if no time had elapsed. figure 4-2: external clock (ec) mode operation switch from switch to frequency oscillator delay sleep/por lfintosc hfintosc 31 khz 125 khz to 8 mhz oscillator warm-up delay (t warm ) sleep/por ec, rc dc ? 20 mhz 2 cycles lfintosc (31 khz) ec, rc dc ? 20 mhz 1 cycle of each sleep/por lp, xt, hs 32 khz to 20 mhz 1024 clock cycles (ost) lfintosc (31 khz) hfintosc 125 khz to 8 mhz 1 s (approx.) osc1/clkin osc2/clkout (1) i/o clock from ext. system pic ? mcu note 1: alternate pin functions are listed in the section 1.0 ?device overview? .
pic16f882/883/884/886/887 41291d-page 64 preliminary ? 2007 microchip technology inc. 4.4.3 lp, xt, hs modes the lp, xt and hs modes support the use of quartz crystal resonators or ceramic resonators connected to osc1 and osc2 (figure 4-3). the mode selects a low, medium or high gain setting of the internal inverter-amplifier to support various resonator types and speed. lp oscillator mode selects the lowest gain setting of the internal inverter-amplifier. lp mode current consumption is the least of the three modes. this mode is designed to drive only 32.768 khz tuning-fork type crystals (watch crystals). xt oscillator mode selects the intermediate gain setting of the internal inverter-amplifier. xt mode current consumption is the medium of the three modes. this mode is best suited to drive resonators with a medium drive level specification. hs oscillator mode selects the highest gain setting of the internal inverter-amplifier. hs mode current consumption is the highest of the three modes. this mode is best suited for resonators that require a high drive setting. figure 4-3 and figure 4-4 show typical circuits for quartz crystal and ceramic resonators, respectively. figure 4-3: quartz crystal operation (lp, xt or hs mode) figure 4-4: ceramic resonator operation (xt or hs mode) note 1: a series resistor (r s ) may be required for quartz crystals with low drive level. 2: the value of r f varies with the oscillator mode selected (typically between 2 m to 10 m ) . c1 c2 quartz r s (1) osc1/clkin r f (2) sleep to internal logic pic ? mcu crystal osc2/clkout note 1: quartz crystal characteristics vary according to type, package and manufacturer. the user should consult the manufacturer data sheets for specifications and recommended application. 2: always verify oscillator performance over the v dd and temperature range that is expected for the application. 3: for oscillator design assistance, reference the following microchip applications notes: ? an826, ? crystal oscillator basics and crystal selection for rfpic ? and pic ? devices ? (ds00826) ? an849, ? basic pic ? oscillator design ? (ds00849) ? an943, ? practical pic ? oscillator analysis and design ? (ds00943) ? an949, ? making your oscillator work ? (ds00949) note 1: a series resistor (r s ) may be required for ceramic resonators with low drive level. 2: the value of r f varies with the oscillator mode selected (typically between 2 m to 10 m ) . 3: an additional parallel feedback resistor (r p ) may be required for proper ceramic resonator operation. c1 c2 ceramic r s (1) osc1/clkin r f (2) sleep to internal logic pic ? mcu r p (3) resonator osc2/clkout
? 2007 microchip technology inc. preliminary 41291d-page 65 pic16f882/883/884/886/887 4.4.4 external rc modes the external resistor-capacitor (rc) modes support the use of an external rc circuit. this allows the designer maximum flexibility in frequency choice while keeping costs to a minimum when clock accuracy is not required. there are two modes: rc and rcio. in rc mode, the rc circuit connects to osc1. osc2/clkout outputs the rc oscillator frequency divided by 4. this signal may be used to provide a clock for external circuitry, synchronization, calibration, test or other application requirements. figure 4-5 shows the external rc mode connections. figure 4-5: external rc modes in rcio mode, the rc circuit is connected to osc1. osc2 becomes an additional general purpose i/o pin. the rc oscillator frequency is a function of the supply voltage, the resistor (r ext ) and capacitor (c ext ) values and the operating temperature. other factors affecting the oscillator frequency are: ? threshold voltage variation ? component tolerances ? packaging variations in capacitance the user also needs to take into account variation due to tolerance of external rc components used. 4.5 internal clock modes the oscillator module has two independent, internal oscillators that can be configured or selected as the system clock source. 1. the hfintosc (high-frequency internal oscillator) is factory calibrated and operates at 8 mhz. the frequency of the hfintosc can be user-adjusted via software using the osctune register (register 4-2). 2. the lfintosc (low-frequency internal oscillator) is uncalibrated and operates at 31 khz. the system clock speed can be selected via software using the internal oscillator frequency select bits ircf<2:0> of the osccon register. the system clock can be selected between external or internal clock sources via the system clock selection (scs) bit of the osccon register. see section 4.6 ?clock switching? for more information. 4.5.1 intosc and intoscio modes the intosc and intoscio modes configure the internal oscillators as the system clock source when the device is programmed using the oscillator selection or the fosc<2:0> bits in the configuration word register 1 (config1). in intosc mode, osc1/clkin is available for general purpose i/o. osc2/clkout outputs the selected internal oscillator frequency divided by 4. the clkout signal may be used to provide a clock for external circuitry, synchronization, calibration, test or other application requirements. in intoscio mode, osc1/clkin and osc2/clkout are available for general purpose i/o. 4.5.2 hfintosc the high-frequency internal oscillator (hfintosc) is a factory calibrated 8 mhz internal clock source. the frequency of the hfintosc can be altered via software using the osctune register (register 4-2). the output of the hfintosc connects to a postscaler and multiplexer (see figure 4-1). one of seven frequencies can be selected via software using the ircf<2:0> bits of the osccon register. see section 4.5.4 ?frequency select bits (ircf)? for more information. the hfintosc is enabled by selecting any frequency between 8 mhz and 125 khz by setting the ircf<2:0> bits of the osccon register 000 . then, set the system clock source (scs) bit of the osccon register to ? 1 ? or enable two-speed start-up by setting the ieso bit in the configuration word register 1 (config1) to ? 1 ?. the hf internal oscillator (hts) bit of the osccon register indicates whether the hfintosc is stable or not. osc2/clkout (1) c ext r ext pic ? mcu osc1/clkin f osc /4 or internal clock v dd v ss recommended values: 10 k r ext 100 k , <3v 3 k r ext 100 k , 3-5v c ext > 20 pf, 2-5v note 1: alternate pin functions are listed in the section 1.0 ?device overview? . 2: output depends upon rc or rcio clock mode. i/o (2)
pic16f882/883/884/886/887 41291d-page 66 preliminary ? 2007 microchip technology inc. 4.5.2.1 osctune register the hfintosc is factory calibrated but can be adjusted in software by writing to the osctune register (register 4-2). the default value of the osctune register is ? 0 ?. the value is a 5-bit two?s complement number. when the osctune register is modified, the hfintosc frequency will begin shifting to the new frequency. code execution continues during this shift. there is no indication that the shift has occurred. osctune does not affect the lfintosc frequency. operation of features that depend on the lfintosc clock source frequency, such as the power-up timer (pwrt), watchdog timer (wdt), fail-safe clock monitor (fscm) and peripherals, are not affected by the change in frequency. register 4-2: osctune: oscillator tuning register u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? tun4 tun3 tun2 tun1 tun0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 tun<4:0>: frequency tuning bits 01111 = maximum frequency 01110 = ? ? ? 00001 = 00000 = oscillator module is running at the calibrated frequency. 11111 = ? ? ? 10000 = minimum frequency
? 2007 microchip technology inc. preliminary 41291d-page 67 pic16f882/883/884/886/887 4.5.3 lfintosc the low-frequency internal oscillator (lfintosc) is an uncalibrated 31 khz internal clock source. the output of the lfintosc connects to a postscaler and multiplexer (see figure 4-1). select 31 khz, via software, using the ircf<2:0> bits of the osccon register. see section 4.5.4 ?frequency select bits (ircf)? for more information. the lfintosc is also the frequency for the power-up timer (pwrt), watchdog timer (wdt) and fail-safe clock monitor (fscm). the lfintosc is enabled by selecting 31 khz (ircf<2:0> bits of the osccon register = 000) as the system clock source (scs bit of the osccon register = 1 ), or when any of the following are enabled: ? two-speed start-up ieso bit of the configuration word register 1 = 1 and ircf<2:0> bits of the osccon register = 000 ? power-up timer (pwrt) ? watchdog timer (wdt) ? fail-safe clock monitor (fscm) the lf internal oscillator (lts) bit of the osccon register indicates whether the lfintosc is stable or not. 4.5.4 frequency select bits (ircf) the output of the 8 mhz hfintosc and 31 khz lfintosc connects to a postscaler and multiplexer (see figure 4-1). the internal oscillator frequency select bits ircf<2:0> of the osccon register select the frequency output of the internal oscillators. one of eight frequencies can be selected via software: ?8 mhz ? 4 mhz (default after reset) ?2 mhz ?1 mhz ? 500 khz ? 250 khz ? 125 khz ? 31 khz (lfintosc) 4.5.5 hfintosc and lfintosc clock switch timing when switching between the lfintosc and the hfintosc, the new oscillator may already be shut down to save power (see figure 4-6). if this is the case, there is a delay after the ircf<2:0> bits of the osccon register are modified before the frequency selection takes place. the lts and hts bits of the osccon register will reflect the current active status of the lfintosc and hfintosc oscillators. the timing of a frequency selection is as follows: 1. ircf<2:0> bits of the osccon register are modified. 2. if the new clock is shut down, a clock start-up delay is started. 3. clock switch circuitry waits for a falling edge of the current clock. 4. clkout is held low and the clock switch circuitry waits for a rising edge in the new clock. 5. clkout is now connected with the new clock. lts and hts bits of the osccon register are updated as required. 6. clock switch is complete. see figure 4-1 for more details. if the internal oscillator speed selected is between 8 mhz and 125 khz, there is no start-up delay before the new frequency is selected. this is because the old and new frequencies are derived from the hfintosc via the postscaler and multiplexer. start-up delay specifications are located in the oscillator tables of section 17.0 ?electrical specifications? . note: following any reset, the ircf<2:0> bits of the osccon register are set to ? 110 ? and the frequency selection is set to 4 mhz. the user can modify the ircf bits to select a different frequency.
pic16f882/883/884/886/887 41291d-page 68 preliminary ? 2007 microchip technology inc. figure 4-6: internal oscillator switch timing hfintosc lfintosc ircf <2:0> system clock hfintosc lfintosc ircf <2:0> system clock 0 = 0 0 = 0 start-up time 2-cycle sync running 2-cycle sync running hfintosc lfintosc (fscm and wdt disabled) hfintosc lfintosc (either fscm or wdt enabled) lfintosc hfintosc ircf <2:0> system clock = 0 ? 0 start-up time 2-cycle sync running lfintosc hfintosc lfintosc turns off unless wdt or fscm is enabled
? 2007 microchip technology inc. preliminary 41291d-page 69 pic16f882/883/884/886/887 4.6 clock switching the system clock source can be switched between external and internal clock sources via software using the system clock select (scs) bit of the osccon register. 4.6.1 system clock select (scs) bit the system clock select (scs) bit of the osccon register selects the system clock source that is used for the cpu and peripherals. ? when the scs bit of the osccon register = 0 , the system clock source is determined by configuration of the fosc<2:0> bits in the configuration word register 1 (config1). ? when the scs bit of the osccon register = 1 , the system clock source is chosen by the internal oscillator frequency selected by the ircf<2:0> bits of the osccon register. after a reset, the scs bit of the osccon register is always cleared. 4.6.2 oscillator start-up time-out status (osts) bit the oscillator start-up time-out status (osts) bit of the osccon register indicates whether the system clock is running from the external clock source, as defined by the fosc<2:0> bits in the configuration word register 1 (config1), or from the internal clock source. in particular, osts indicates that the oscillator start-up timer (ost) has timed out for lp, xt or hs modes. 4.7 two-speed clock start-up mode two-speed start-up mode provides additional power savings by minimizing the latency between external oscillator start-up and code execution. in applications that make heavy use of the sleep mode, two-speed start-up will remove the external oscillator start-up time from the time spent awake and can reduce the overall power consumption of the device. this mode allows the application to wake-up from sleep, perform a few instructions using the intosc as the clock source and go back to sleep without waiting for the primary oscillator to become stable. when the oscillator module is configured for lp, xt or hs modes, the oscillator start-up timer (ost) is enabled (see section 4.4.1 ?oscillator start-up timer (ost)? ). the ost will suspend program execution until 1024 oscillations are counted. two-speed start-up mode minimizes the delay in code execution by operating from the internal oscillator as the ost is counting. when the ost count reaches 1024 and the osts bit of the osccon register is set, program execution switches to the external oscillator. 4.7.1 two-speed start-up mode configuration two-speed start-up mode is configured by the following settings: ? ieso (of the configuration word register 1) = 1 ; internal/external switchover bit (two-speed start-up mode enabled). ? scs (of the osccon register) = 0 . ? fosc<2:0> bits in the configuration word register 1 (config1) configured for lp, xt or hs mode. two-speed start-up mode is entered after: ? power-on reset (por) and, if enabled, after power-up timer (pwrt) has expired, or ? wake-up from sleep. if the external clock oscillator is configured to be anything other than lp, xt or hs mode, then two-speed start-up is disabled. this is because the external clock oscillator does not require any stabilization time after por or an exit from sleep. 4.7.2 two-speed start-up sequence 1. wake-up from power-on reset or sleep. 2. instructions begin execution by the internal oscillator at the frequency set in the ircf<2:0> bits of the osccon register. 3. ost enabled to count 1024 clock cycles. 4. ost timed out, wait for falling edge of the internal oscillator. 5. osts is set. 6. system clock held low until the next falling edge of new clock (lp, xt or hs mode). 7. system clock is switched to external clock source. note: any automatic clock switch, which may occur from two-speed start-up or fail-safe clock monitor, does not update the scs bit of the osccon register. the user can monitor the osts bit of the osccon register to determine the current system clock source. note: executing a sleep instruction will abort the oscillator start-up time and will cause the osts bit of the osccon register to remain clear.
pic16f882/883/884/886/887 41291d-page 70 preliminary ? 2007 microchip technology inc. 4.7.3 checking two-speed clock status checking the state of the osts bit of the osccon register will confirm if the microcontroller is running from the external clock source, as defined by the fosc<2:0> bits in the configuration word register 1 (config1), or the internal oscillator. figure 4-7: two-speed start-up 0 1 1022 1023 pc + 1 t ost t hfintosc osc1 osc2 program counter system clock pc - n pc
? 2007 microchip technology inc. preliminary 41291d-page 71 pic16f882/883/884/886/887 4.8 fail-safe clock monitor the fail-safe clock monitor (fscm) allows the device to continue operating should the external oscillator fail. the fscm can detect oscillator failure any time after the oscillator start-up timer (ost) has expired. the fscm is enabled by setting the fcmen bit in the configuration word register 1 (config1). the fscm is applicable to all external oscillator modes (lp, xt, hs, ec, rc and rcio). figure 4-8: fscm block diagram 4.8.1 fail-safe detection the fscm module detects a failed oscillator by comparing the external oscillator to the fscm sample clock. the sample clock is generated by dividing the lfintosc by 64. see figure 4-8. inside the fail detector block is a latch. the external clock sets the latch on each falling edge of the external clock. the sample clock clears the latch on each rising edge of the sample clock. a failure is detected when an entire half-cycle of the sample clock elapses before the primary clock goes low. 4.8.2 fail-safe operation when the external clock fails, the fscm switches the device clock to an internal clock source and sets the bit flag osfif of the pir2 register. setting this flag will generate an interrupt if the osfie bit of the pie2 register is also set. the device firmware can then take steps to mitigate the problems that may arise from a failed clock. the system clock will continue to be sourced from the internal clock source until the device firmware successfully restarts the external oscillator and switches back to external operation. the internal clock source chosen by the fscm is determined by the ircf<2:0> bits of the osccon register. this allows the internal oscillator to be configured before a failure occurs. 4.8.3 fail-safe condition clearing the fail-safe condition is cleared after a reset, executing a sleep instruction or toggling the scs bit of the osccon register. when the scs bit is toggled, the ost is restarted. while the ost is running, the device continues to operate from the intosc selected in osccon. when the ost times out, the fail-safe condition is cleared and the device will be operating from the external clock source. the fail-safe condition must be cleared before the osfif flag can be cleared. 4.8.4 reset or wake-up from sleep the fscm is designed to detect an oscillator failure after the oscillator start-up timer (ost) has expired. the ost is used after waking up from sleep and after any type of reset. the ost is not used with the ec or rc clock modes so that the fscm will be active as soon as the reset or wake-up has completed. when the fscm is enabled, the two-speed start-up is also enabled. therefore, the device will always be executing code while the ost is operating. external lfintosc 64 s r q 31 khz (~32 s) 488 hz (~2 ms) clock monitor latch clock failure detected oscillator clock q sample clock note: due to the wide range of oscillator start-up times, the fail-safe circuit is not active during oscillator start-up (i.e., after exiting reset or sleep). after an appropriate amount of time, the user should check the osts bit of the osccon register to verify the oscillator start-up and that the system clock switchover has successfully completed.
pic16f882/883/884/886/887 41291d-page 72 preliminary ? 2007 microchip technology inc. figure 4-9: fscm timing diagram table 4-2: summary of registers associated with clock sources oscfif system clock output sample clock failure detected oscillator failure note: the system clock is normally at a much higher frequency than the sample clock. the relative frequencies in this example have been chosen for clarity. (q) te s t test test clock monitor output name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets (1) config1 (2) cpd cp mclre pwrte wdte fosc2 fosc1 fosc0 ? ? osccon ? ircf2 ircf1 ircf0 osts hts lts scs -110 x000 -110 x000 osctune ? ? ? tun4 tun3 tun2 tun1 tun0 ---0 0000 ---u uuuu pie2 osfie c2ie c1ie eeie bclie ulpwuie ? ccp2ie 0000 00-0 0000 00-0 pir2 osfif c2if c1if eeif bclif ulpwuif ? ccp2if 0000 00-0 0000 00-0 legend: x = unknown, u = unchanged, ? = unimplemented locations read as ? 0 ?. shaded cells are not used by oscillators. note 1: other (non power-up) resets include mclr reset and watchdog timer reset during normal operation. 2: see configuration word register 1 (register 14-1) for operation of all register bits.
? 2007 microchip technology inc. preliminary ds41291d-page 73 pic16f882/883/884/886/887 5.0 timer0 module the timer0 module is an 8-bit timer/counter with the following features: ? 8-bit timer/counter register (tmr0) ? 8-bit prescaler (shared with watchdog timer) ? programmable internal or external clock source ? programmable external clock edge selection ? interrupt on overflow figure 5-1 is a block diagram of the timer0 module. 5.1 timer0 operation when used as a timer, the timer0 module can be used as either an 8-bit timer or an 8-bit counter. 5.1.1 8-bit timer mode when used as a timer, the timer0 module will increment every instruction cycle (without prescaler). timer mode is selected by clearing the t0cs bit of the option register to ? 0 ?. when tmr0 is written, the increment is inhibited for two instruction cycles immediately following the write. 5.1.2 8-bit counter mode when used as a counter, the timer0 module will increment on every rising or falling edge of the t0cki pin. the incrementing edge is determined by the t0se bit of the option register. counter mode is selected by setting the t0cs bit of the option register to ? 1 ?. figure 5-1: timer0/wdt prescaler block diagram note: the value written to the tmr0 register can be adjusted, in order to account for the two instruction cycle delay when tmr0 is written. t0cki t0se pin tmr0 watchdog timer wdt time-out ps<2:0> wdte data bus set flag bit t0if on overflow t0cs note 1: t0se, t0cs, psa, ps<2:0> are bits in the option register. 2: swdten and wdtps<3:0> are bits in the wdtcon register. 3: wdte bit is in the configuration word register1. 0 1 0 1 0 1 8 8 8-bit prescaler 0 1 f osc /4 psa psa psa 16-bit prescaler 16 wdtps<3:0> 31 khz intosc swdten sync 2 tcy
pic16f882/883/884/886/887 ds41291d-page 74 preliminary ? 2007 microchip technology inc. 5.1.3 software programmable prescaler a single software programmable prescaler is available for use with either timer0 or the watchdog timer (wdt), but not both simultaneously. the prescaler assignment is controlled by the psa bit of the option register. to assign the prescaler to timer0, the psa bit must be cleared to a ? 0 ?. there are 8 prescaler options for the timer0 module ranging from 1:2 to 1:256. the prescale values are selectable via the ps<2:0> bits of the option register. in order to have a 1:1 prescaler value for the timer0 module, the prescaler must be assigned to the wdt module. the prescaler is not readable or writable. when assigned to the timer0 module, all instructions writing to the tmr0 register will clear the prescaler. when the prescaler is assigned to wdt, a clrwdt instruction will clear the prescaler along with the wdt. 5.1.3.1 switching prescaler between timer0 and wdt modules as a result of having the prescaler assigned to either timer0 or the wdt, it is possible to generate an unintended device reset when switching prescaler values. when changing the prescaler assignment from timer0 to the wdt module, the instruction sequence shown in example 5-1, must be executed. example 5-1: changing prescaler (timer0 wdt) when changing the prescaler assignment from the wdt to the timer0 module, the following instruction sequence must be executed (see example 5-2). example 5-2: changing prescaler (wdt timer0) 5.1.4 timer0 interrupt timer0 will generate an interrupt when the tmr0 register overflows from ffh to 00h. the t0if interrupt flag bit of the intcon register is set every time the tmr0 register overflows, regardless of whether or not the timer0 interrupt is enabled. the t0if bit must be cleared in software. the timer0 interrupt enable is the t0ie bit of the intcon register. 5.1.5 using timer0 with an external clock when timer0 is in counter mode, the synchronization of the t0cki input and the timer0 register is accom- plished by sampling the prescaler output on the q2 and q4 cycles of the internal phase clocks. therefore, the high and low periods of the external clock source must meet the timing requirements as shown in the section 17.0 ?electrical specifications? . banksel tmr0 ; clrwdt ;clear wdt clrf tmr0 ;clear tmr0 and ;prescaler banksel option_reg ; bsf option_reg,psa ;select wdt clrwdt ; ; movlw b?11111000? ;mask prescaler andwf option_reg,w ;bits iorlw b?00000101? ;set wdt prescaler movwf option_reg ;to 1:32 note: the timer0 interrupt cannot wake the processor from sleep since the timer is frozen during sleep. clrwdt ;clear wdt and ;prescaler banksel option_reg ; movlw b?11110000? ;mask tmr0 select and andwf option_reg,w ;prescaler bits iorlw b?00000011? ;set prescale to 1:16 movwf option_reg ;
? 2007 microchip technology inc. preliminary ds41291d-page 75 pic16f882/883/884/886/887 table 5-1: summary of registers associated with timer0 register 5-1: option_reg: option register r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 rbpu intedg t0cs t0se psa ps2 ps1 ps0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 rbpu : portb pull-up enable bit 1 = portb pull-ups are disabled 0 = portb pull-ups are enabled by individual port latch values bit 6 intedg: interrupt edge select bit 1 = interrupt on rising edge of int pin 0 = interrupt on falling edge of int pin bit 5 t0cs: tmr0 clock source select bit 1 = transition on t0cki pin 0 = internal instruction cycle clock (f osc /4) bit 4 t0se: tmr0 source edge select bit 1 = increment on high-to-low transition on t0cki pin 0 = increment on low-to-high transition on t0cki pin bit 3 psa: prescaler assignment bit 1 = prescaler is assigned to the wdt 0 = prescaler is assigned to the timer0 module bit 2-0 ps<2:0>: prescaler rate select bits note 1: a dedicated 16-bit wdt postscaler is available. see section 14.5 ?watchdog timer (wdt)? for more information. 000 001 010 011 100 101 110 111 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 1 : 256 1 : 1 1 : 2 1 : 4 1 : 8 1 : 16 1 : 32 1 : 64 1 : 128 bit value tmr0 rate wdt rate name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets tmr0 timer0 module register xxxx xxxx uuuu uuuu intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 1111 1111 legend: ? = unimplemented locations, read as ? 0 ?, u = unchanged, x = unknown. shaded cells are not used by the timer0 module.
pic16f882/883/884/886/887 ds41291d-page 76 preliminary ? 2007 microchip technology inc. 6.0 timer1 module with gate control the timer1 module is a 16-bit timer/counter with the following features: ? 16-bit timer/counter register pair (tmr1h:tmr1l) ? programmable internal or external clock source ? 3-bit prescaler ? optional lp oscillator ? synchronous or asynchronous operation ? timer1 gate (count enable) via comparator or t1g pin ? interrupt on overflow ? wake-up on overflow (external clock, asynchronous mode only) ? time base for the capture/compare function ? special event trigger (with eccp) ? comparator output synchronization to timer1 clock figure 6-1 is a block diagram of the timer1 module. 6.1 timer1 operation the timer1 module is a 16-bit incrementing counter which is accessed through the tmr1h:tmr1l register pair. writes to tmr1h or tmr1l directly update the counter. when used with an internal clock source, the module is a timer. when used with an external clock source, the module can be used as either a timer or counter. 6.2 clock source selection the tmr1cs bit of the t1con register is used to select the clock source. when tmr1cs = 0 , the clock source is f osc /4. when tmr1cs = 1 , the clock source is supplied externally. figure 6-1: timer1 block diagram clock source tmr1cs f osc /4 0 t1cki pin 1 tmr1h tmr1l t1sync t1ckps<1:0> prescaler 1, 2, 4, 8 0 1 synchronized clock input 2 set flag bit tmr1if on overflow tmr1 (2) tmr1ge tmr1on 1 0 c2out t1gss t1ginv to c2 comparator module timer1 clock note 1: st buffer is low power type when using lp oscillator, or high speed type when using t1cki. 2: timer1 register increments on rising edge. 3: synchronize does not operate while in sleep. en t1g t1 osc f osc /4 internal clock 1 0 t1osi t1oso t1oscen 1 0 t1cki tmr1cs (1) synchronize (3) det sleep input
? 2007 microchip technology inc. preliminary ds41291d-page 77 pic16f882/883/884/886/887 6.2.1 internal clock source when the internal clock source is selected the tmr1h:tmr1l register pair will increment on multiples of f osc as determined by the timer1 prescaler. 6.2.2 external clock source when the external clock source is selected, the timer1 module may work as a timer or a counter. when counting, timer1 is incremented on the rising edge of the external clock input t1cki. in addition, the counter mode clock can be synchronized to the microcontroller system clock or run asynchronously. if an external clock oscillator is needed (and the microcontroller is using the intosc without clkout), timer1 can use the lp oscillator as a clock source. 6.3 timer1 prescaler timer1 has four prescaler options allowing 1, 2, 4 or 8 divisions of the clock input. the t1ckps bits of the t1con register control the prescale counter. the prescale counter is not directly readable or writable; however, the prescaler counter is cleared upon a write to tmr1h or tmr1l. 6.4 timer1 oscillator a low-power 32.768 khz crystal oscillator is built-in between pins t1osi (input) and t1oso (amplifier output). the oscillator is enabled by setting the t1oscen control bit of the t1con register. the oscillator will continue to run during sleep. the timer1 oscillator is identical to the lp oscillator. the user must provide a software time delay to ensure proper oscillator start-up. trisc0 and trisc1 bits are set when the timer1 oscillator is enabled. rc0 and rc1 bits read as ? 0 ? and trisc0 and trisc1 bits read as ? 1 ?. 6.5 timer1 operation in asynchronous counter mode if control bit t1sync of the t1con register is set, the external clock input is not synchronized. the timer continues to increment asynchronous to the internal phase clocks. the timer will continue to run during sleep and can generate an interrupt on overflow, which will wake-up the processor. however, special precautions in software are needed to read/write the timer (see section 6.5.1 ?reading and writing timer1 in asynchronous counter mode? ). 6.5.1 reading and writing timer1 in asynchronous counter mode reading tmr1h or tmr1l while the timer is running from an external asynchronous clock will ensure a valid read (taken care of in hardware). however, the user should keep in mind that reading the 16-bit timer in two 8-bit values itself, poses certain problems, since the timer may overflow between the reads. for writes, it is recommended that the user simply stop the timer and write the desired values. a write contention may occur by writing to the timer registers, while the register is incrementing. this may produce an unpredictable value in the tmr1h:ttmr1l register pair. 6.6 timer1 gate timer1 gate source is software configurable to be the t1g pin or the output of comparator c2. this allows the device to directly time external events using t1g or analog events using comparator c2. see the cm2con1 register (register 8-3) for selecting the timer1 gate source. this feature can simplify the software for a delta-sigma a/d converter and many other applications. for more information on delta-sigma a/d converters, see the microchip web site (www.microchip.com). timer1 gate can be inverted using the t1ginv bit of the t1con register, whether it originates from the t1g pin or comparator c2 output. this configures timer1 to measure either the active-high or active-low time between events. note: in counter mode, a falling edge must be registered by the counter prior to the first incrementing rising edge. note: the oscillator requires a start-up and stabilization time before use. thus, t1oscen should be set and a suitable delay observed prior to enabling timer1. note: when switching from synchronous to asynchronous operation, it is possible to skip an increment. when switching from asynchronous to synchronous operation, it is possible to produce a single spurious increment. note: tmr1ge bit of the t1con register must be set to use either t1g or c2out as the timer1 gate source. see register 8-3 for more information on selecting the timer1 gate source.
pic16f882/883/884/886/887 ds41291d-page 78 preliminary ? 2007 microchip technology inc. 6.7 timer1 interrupt the timer1 register pair (tmr1h:tmr1l) increments to ffffh and rolls over to 0000h. when timer1 rolls over, the timer1 interrupt flag bit of the pir1 register is set. to enable the interrupt on rollover, you must set these bits: ? timer1 interrupt enable bit of the pie1 register ? peie bit of the intcon register ? gie bit of the intcon register the interrupt is cleared by clearing the tmr1if bit in the interrupt service routine. 6.8 timer1 operation during sleep timer1 can only operate during sleep when setup in asynchronous counter mode. in this mode, an external crystal or clock source can be used to increment the counter. to set up the timer to wake the device: ? tmr1on bit of the t1con register must be set ? tmr1ie bit of the pie1 register must be set ? peie bit of the intcon register must be set the device will wake-up on an overflow and execute the next instruction. if the gie bit of the intcon register is set, the device will call the interrupt service routine (0004h). 6.9 eccp capture/compare time base the eccp module uses the tmr1h:tmr1l register pair as the time base when operating in capture or compare mode. in capture mode, the value in the tmr1h:tmr1l register pair is copied into the ccprxh:ccprxl register pair on a configured event. in compare mode, an event is triggered when the value ccprxh:ccprxl register pair matches the value in the tmr1h:tmr1l register pair. this event can be a special event trigger. see section 11.0 ?capture/compare/pwm modules (ccp1 and ccp2)? for more information. 6.10 eccp special event trigger if an eccp is configured to trigger a special event, the trigger will clear the tmr1h:tmr1l register pair. this special event does not cause a timer1 interrupt. the eccp module may still be configured to generate a eccp interrupt. in this mode of operation, the ccprxh:ccprxl register pair effectively becomes the period register for timer1. timer1 should be synchronized to the f osc to utilize the special event trigger. asynchronous operation of timer1 can cause a special event trigger to be missed. in the event that a write to tmr1h or tmr1l coincides with a special event trigger from the eccp, the write will take precedence. for more information, see section 11.0 ?capture/compare/pwm modules (ccp1 and ccp2)? . 6.11 comparator synchronization the same clock used to increment timer1 can also be used to synchronize the comparator output. this feature is enabled in the comparator module. when using the comparator for timer1 gate, the comparator output should be synchronized to timer1. this ensures timer1 does not miss an increment if the comparator changes. for more information, see section 8.0 ?comparator module? . figure 6-2: timer1 incrementing edge note: the tmr1h:ttmr1l register pair and the tmr1if bit should be cleared before enabling interrupts. t1cki = 1 when tmr1 enabled t1cki = 0 when tmr1 enabled note 1: arrows indicate counter increments. 2: in counter mode, a falling edge must be registered by the counter prior to the first incrementing rising edge of the clock.
? 2007 microchip technology inc. preliminary ds41291d-page 79 pic16f882/883/884/886/887 6.12 timer1 control register the timer1 control register (t1con), shown in register 6-1, is used to control timer1 and select the various features of the timer1 module. register 6-1: t1con: timer1 control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 t1ginv (1) tmr1ge (2) t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 t1ginv: timer1 gate invert bit (1) 1 = timer1 gate is active-high (timer1 counts when gate is high) 0 = timer1 gate is active-low (timer1 counts when gate is low) bit 6 tmr1ge: timer1 gate enable bit (2) if tmr1on = 0 : this bit is ignored if tmr1on = 1 : 1 = timer1 is on if timer1 gate is not active 0 = timer1 is on bit 5-4 t1ckps<1:0>: timer1 input clock prescale select bits 11 = 1:8 prescale value 10 = 1:4 prescale value 01 = 1:2 prescale value 00 = 1:1 prescale value bit 3 t1oscen: lp oscillator enable control bit 1 = lp oscillator is enabled for timer1 clock 0 = lp oscillator is off bit 2 t1sync : timer1 external clock input synchronization control bit tmr1cs = 1 : 1 = do not synchronize external clock input 0 = synchronize external clock input tmr1cs = 0 : this bit is ignored. timer1 uses the internal clock bit 1 tmr1cs: timer1 clock source select bit 1 = external clock from t1cki pin (on the rising edge) 0 = internal clock (f osc /4) bit 0 tmr1on: timer1 on bit 1 = enables timer1 0 = stops timer1 note 1: t1ginv bit inverts the timer1 gate logic, regardless of source. 2: tmr1ge bit must be set to use either t1g pin or c2out, as selected by the t1gss bit of the cm2con1 register, as a timer1 gate source.
pic16f882/883/884/886/887 ds41291d-page 80 preliminary ? 2007 microchip technology inc. table 6-1: summary of registers associated with timer1 name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets cm2con1 mc1out mc2out c1rsel c2rsel ? ? t1gss c2sync 0000 --10 0000 --10 intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x pie1 ? adie rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 pir1 ? adif rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 tmr1h holding register for the most significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu tmr1l holding register for the least significant byte of the 16-bit tmr1 register xxxx xxxx uuuu uuuu t1con t1ginv tmr1ge t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on 0000 0000 uuuu uuuu legend: x = unknown, u = unchanged, ? = unimplemented, read as ? 0 ?. shaded cells are not used by the timer1 module.
? 2007 microchip technology inc. preliminary ds41291d-page 81 pic16f882/883/884/886/887 7.0 timer2 module the timer2 module is an eight-bit timer with the following features: ? 8-bit timer register (tmr2) ? 8-bit period register (pr2) ? interrupt on tmr2 match with pr2 ? software programmable prescaler (1:1, 1:4, 1:16) ? software programmable postscaler (1:1 to 1:16) see figure 7-1 for a block diagram of timer2. 7.1 timer2 operation the clock input to the timer2 module is the system instruction clock (f osc /4). the clock is fed into the timer2 prescaler, which has prescale options of 1:1, 1:4 or 1:16. the output of the prescaler is then used to increment the tmr2 register. the values of tmr2 and pr2 are constantly compared to determine when they match. tmr2 will increment from 00h until it matches the value in pr2. when a match occurs, two things happen: ? tmr2 is reset to 00h on the next increment cycle ? the timer2 postscaler is incremented the match output of the timer2/pr2 comparator is then fed into the timer2 postscaler. the postscaler has postscale options of 1:1 to 1:16 inclusive. the output of the timer2 postscaler is used to set the tmr2if interrupt flag bit in the pir1 register. the tmr2 and pr2 registers are both fully readable and writable. on any reset, the tmr2 register is set to 00h and the pr2 register is set to ffh. timer2 is turned on by setting the tmr2on bit in the t2con register to a ? 1 ?. timer2 is turned off by clearing the tmr2on bit to a ? 0 ?. the timer2 prescaler is controlled by the t2ckps bits in the t2con register. the timer2 postscaler is controlled by the toutps bits in the t2con register. the prescaler and postscaler counters are cleared when: ? a write to tmr2 occurs. ? a write to t2con occurs. ? any device reset occurs (power-on reset, mclr reset, watchdog timer reset, or brown-out reset). figure 7-1: timer2 block diagram note: tmr2 is not cleared when t2con is written. comparator tmr2 sets flag tmr2 output reset postscaler prescaler pr2 2 f osc /4 1:1 to 1:16 1:1, 1:4, 1:16 eq 4 bit tmr2if toutps<3:0> t2ckps<1:0>
pic16f882/883/884/886/887 ds41291d-page 82 preliminary ? 2007 microchip technology inc. table 7-1: summary of associated timer2 registers register 7-1: t2con: timer2 control register u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-3 toutps<3:0>: timer2 output postscaler select bits 0000 = 1:1 postscaler 0001 = 1:2 postscaler 0010 = 1:3 postscaler 0011 = 1:4 postscaler 0100 = 1:5 postscaler 0101 = 1:6 postscaler 0110 = 1:7 postscaler 0111 = 1:8 postscaler 1000 = 1:9 postscaler 1001 = 1:10 postscaler 1010 = 1:11 postscaler 1011 = 1:12 postscaler 1100 = 1:13 postscaler 1101 = 1:14 postscaler 1110 = 1:15 postscaler 1111 = 1:16 postscaler bit 2 tmr2on: timer2 on bit 1 = timer2 is on 0 = timer2 is off bit 1-0 t2ckps<1:0>: timer2 clock prescale select bits 00 =prescaler is 1 01 =prescaler is 4 1x = prescaler is 16 name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x pie1 ? adie rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 pir1 ? adif rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 pr2 timer2 module period register 1111 1111 1111 1111 tmr2 holding register for the 8-bit tmr2 register 0000 0000 0000 0000 t2con ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 -000 0000 legend: x = unknown, u = unchanged, ? = unimplemented read as ? 0 ?. shaded cells are not used for timer2 module.
? 2007 microchip technology inc. preliminary ds41291d-page 83 pic16f882/883/884/886/887 8.0 comparator module comparators are used to interface analog circuits to a digital circuit by comparing two analog voltages and providing a digital indication of their relative magnitudes. the comparators are very useful mixed signal building blocks because they provide analog functionality independent of the program execution. the analog comparator module includes the following features: ? independent comparator control ? programmable input selection ? comparator output is available internally/externally ? programmable output polarity ? interrupt-on-change ? wake-up from sleep ?pwm shutdown ? timer1 gate (count enable) ? output synchronization to timer1 clock input ?sr latch ? programmable and fixed voltage reference 8.1 comparator overview a single comparator is shown in figure 8-1 along with the relationship between the analog input levels and the digital output. when the analog voltage at v in + is less than the analog voltage at v in -, the output of the comparator is a digital low level. when the analog voltage at v in + is greater than the analog voltage at v in -, the output of the comparator is a digital high level. figure 8-1: single comparator note: only comparator c2 can be linked to timer1. ? + v in + v in - output output v in + v in - note: the black areas of the output of the comparator represents the uncertainty due to input offsets and response time.
pic16f882/883/884/886/887 ds41291d-page 84 preliminary ? 2007 microchip technology inc. figure 8-2: comparator c1 simplified block diagram figure 8-3: comparator c2 simplified block diagram note 1: when c1on = 0 , the c1 comparator will produce a ? 0 ? output to the xor gate. 2: q1 and q3 are phases of the four-phase system clock (f osc ). 3: q1 is held high during sleep mode. c1pol c1out to pwm logic rd_cm1con0 set c1if to dq en q1 data bus c1pol dq en cl q3*rd_cm1con0 reset c1out (to sr latch) mux c1 0 1 2 3 c1on (1) c1ch<1:0> 2 0 1 c1r mux c1v in - c1v in + c12in0- c12in1- c12in2- c12in3- c1in+ + - 0 1 mux cv ref c1r sel fixedref c1v ref mux c2 c2pol c2out 0 1 2 3 c2on (1) c2ch<1:0> 2 0 1 c2r from timer1 clock note 1: when c2on = 0 , the c2 comparator will produce a ? 0 ? output to the xor gate. 2: q1 and q3 are phases of the four-phase system clock (f osc ). 3: q1 is held high during sleep mode. mux dq en dq en cl dq rd_cm2con0 q3*rd_cm2con0 q1 set c2if to reset c2v in - c2v in + syncc2out c2in+ c12in0- c12in1- c2in2- c2in3- 0 1 c2sync c2pol data bus mux to timer1 gate, sr latch 0 1 mux cv ref c2r sel fixedref c2v ref and other peripherals
? 2007 microchip technology inc. preliminary ds41291d-page 85 pic16f882/883/884/886/887 8.2 comparator control each comparator has a separate control and configuration register: cm1con0 for comparator c1 and cm2con0 for comparator c2. in addition, comparator c2 has a second control register, cm2con1, for controlling the interaction with timer1 and simultaneous reading of both comparator outputs. the cm1con0 and cm2con0 registers (see registers 8-1 and 8-2, respectively) contain the control and status bits for the following: ? enable ? input selection ? reference selection ?output selection ? output polarity 8.2.1 comparator enable setting the cxon bit of the cmxcon0 register enables the comparator for operation. clearing the cxon bit disables the comparator resulting in minimum current consumption. 8.2.2 comparator input selection the cxch<1:0> bits of the cmxcon0 register direct one of four analog input pins to the comparator inverting input. 8.2.3 comparator reference selection setting the cxr bit of the cmxcon0 register directs an internal voltage reference or an analog input pin to the non-inverting input of the comparator. see section 8.10 ?comparator voltage reference? for more information on the internal voltage reference module. 8.2.4 comparator output selection the output of the comparator can be monitored by reading either the cxout bit of the cmxcon0 register or the mcxout bit of the cm2con1 register. in order to make the output available for an external connection, the following conditions must be true: ? cxoe bit of the cmxcon0 register must be set ? corresponding tris bit must be cleared ? cxon bit of the cmxcon0 register must be set 8.2.5 comparator output polarity inverting the output of the comparator is functionally equivalent to swapping the comparator inputs. the polarity of the comparator output can be inverted by setting the cxpol bit of the cmxcon0 register. clearing the cxpol bit results in a non-inverted output. table 8-1 shows the output state versus input conditions, including polarity control. 8.3 comparator response time the comparator output is indeterminate for a period of time after the change of an input source or the selection of a new reference voltage. this period is referred to as the response time. the response time of the comparator differs from the settling time of the voltage reference. therefore, both of these times must be considered when determining the total response time to a comparator input change. see the comparator and voltage reference specifications in section 17.0 ?electrical specifications? for more details. note: to use c x in+ and c x in- pins as analog inputs, the appropriate bits must be set in the ansel and anselh registers and the corresponding tris bits must also be set to disable the output drivers. note 1: the cxoe bit overrides the port data latch. setting the cxon has no impact on the port override. 2: the internal output of the comparator is latched with each instruction cycle. unless otherwise specified, external outputs are not latched. table 8-1: comparator output state vs. input conditions input condition cxpol cxout cxv in - > cxv in + 00 cxv in - < cxv in + 01 cxv in - > cxv in + 11 cxv in - < cxv in + 10
pic16f882/883/884/886/887 ds41291d-page 86 preliminary ? 2007 microchip technology inc. 8.4 comparator interrupt operation the comparator interrupt flag can be set whenever there is a change in the output value of the comparator. changes are recognized by means of a mismatch circuit which consists of two latches and an exclusive- or gate (see figures 8-2 and 8-3). one latch is updated with the comparator output level when the cmxcon0 register is read. this latch retains the value until the next read of the cmxcon0 register or the occurrence of a reset. the other latch of the mismatch circuit is updated on every q1 system clock. a mismatch condition will occur when a comparator output change is clocked through the second latch on the q1 clock cycle. at this point the two mismatch latches have opposite output levels which is detected by the exclusive-or gate and fed to the interrupt circuitry. the mismatch condition persists until either the cmxcon0 register is read or the comparator output returns to the previous state. the comparator interrupt is set by the mismatch edge and not the mismatch level. this means that the inter- rupt flag can be reset without the additional step of reading or writing the cmxcon0 register to clear the mismatch registers. when the mismatch registers are cleared, an interrupt will occur upon the comparator?s return to the previous state, otherwise no interrupt will be generated. software will need to maintain information about the status of the comparator output, as read from the cmxcon0 register, or cm2con1 register, to determine the actual change that has occurred. the cxif bit of the pir2 register is the comparator interrupt flag. this bit must be reset in software by clearing it to ? 0 ?. since it is also possible to write a ? 1 ? to this register, an interrupt can be generated. the cxie bit of the pie2 register and the peie and gie bits of the intcon register must all be set to enable comparator interrupts. if any of these bits are cleared, the interrupt is not enabled, although the cxif bit of the pir2 register will still be set if an interrupt condition occurs. figure 8-4: comparator interrupt timing w/o cmxcon0 read figure 8-5: comparator interrupt timing with cmxcon0 read note 1: a write operation to the cmxcon0 register will also clear the mismatch condition because all writes include a read operation at the beginning of the write cycle. 2: comparator interrupts will operate correctly regardless of the state of cxoe. note 1: if a change in the cmxcon0 register (cxout) should occur when a read oper- ation is being executed (start of the q2 cycle), then the cxif of the pir2 register interrupt flag may not get set. 2: when either comparator is first enabled, bias circuitry in the comparator module may cause an invalid output from the comparator until the bias circuitry is stable. allow about 1 s for bias settling then clear the mismatch condition and interrupt flags before enabling comparator interrupts. q1 q3 cxin+ cxout set cxif (edge) cxif t rt reset by software q1 q3 cxin+ cxout set cxif (edge) cxif t rt reset by software cleared by cmxcon0 read
? 2007 microchip technology inc. preliminary ds41291d-page 87 pic16f882/883/884/886/887 8.5 operation during sleep the comparator, if enabled before entering sleep mode, remains active during sleep. the additional current consumed by the comparator is shown separately in the section 17.0 ?electrical specifications? . if the comparator is not used to wake the device, power consumption can be minimized while in sleep mode by turning off the comparator. each comparator is turned off by clearing the cxon bit of the cmxcon0 register. a change to the comparator output can wake-up the device from sleep. to enable the comparator to wake the device from sleep, the cxie bit of the pie2 register and the peie bit of the intcon register must be set. the instruction following the sleep instruction always executes following a wake from sleep. if the gie bit of the intcon register is also set, the device will then execute the interrupt service routine. 8.6 effects of a reset a device reset forces the cmxcon0 and cm2con1 registers to their reset states. this forces both comparators and the voltage references to their off states.
pic16f882/883/884/886/887 ds41291d-page 88 preliminary ? 2007 microchip technology inc. register 8-1: cm1con0: comparator c1 control register 0 r/w-0 r-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 c1on c1out c1oe c1pol ? c1r c1ch1 c1ch0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 c1on: comparator c1 enable bit 1 = comparator c1 is enabled 0 = comparator c1 is disabled bit 6 c1out: comparator c1 output bit if c1pol = 1 (inverted polarity): c1out = 0 when c1v in + > c1v in - c1out = 1 when c1v in + < c1v in - if c1pol = 0 (non-inverted polarity): c1out = 1 when c1v in + > c1v in - c1out = 0 when c1v in + < c1v in - bit 5 c1oe: comparator c1 output enable bit 1 = c1out is present on the c1out pin (1) 0 = c1out is internal only bit 4 c1pol: comparator c1 output polarity select bit 1 = c1out logic is inverted 0 = c1out logic is not inverted bit 3 unimplemented: read as ? 0 ? bit 2 c1r: comparator c1 reference select bit (non-inverting input) 1 = c1v in + connects to c1v ref output 0 = c1v in + connects to c1in+ pin bit 1-0 c1ch<1:0>: comparator c1 channel select bit 00 = c12in0- pin of c1 connects to c1v in - 01 = c12in1- pin of c1 connects to c1v in - 10 = c12in2- pin of c1 connects to c1v in - 11 = c12in3- pin of c1 connects to c1v in - note 1: comparator output requires the following three conditions: c1oe = 1 , c1on = 1 and corresponding port tris bit = 0 .
? 2007 microchip technology inc. preliminary ds41291d-page 89 pic16f882/883/884/886/887 register 8-2: cm2con0: comparator c2 control register 0 r/w-0 r-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 c2on c2out c2oe c2pol ? c2r c2ch1 c2ch0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 c2on: comparator c2 enable bit 1 = comparator c2 is enabled 0 = comparator c2 is disabled bit 6 c2out: comparator c2 output bit if c2pol = 1 (inverted polarity): c2out = 0 when c2v in + > c2v in - c2out = 1 when c2v in + < c2v in - if c2pol = 0 (non-inverted polarity): c2out = 1 when c2v in + > c2v in - c2out = 0 when c2v in + < c2v in - bit 5 c2oe: comparator c2 output enable bit 1 = c2out is present on c2out pin (1) 0 = c2out is internal only bit 4 c2pol: comparator c2 output polarity select bit 1 = c2out logic is inverted 0 = c2out logic is not inverted bit 3 unimplemented: read as ? 0 ? bit 2 c2r: comparator c2 reference select bits (non-inverting input) 1 = c2v in + connects to c2v ref 0 = c2v in + connects to c2in+ pin bit 1-0 c2ch<1:0>: comparator c2 channel select bits 00 = c12in0- pin of c2 connects to c2v in - 01 = c12in1- pin of c2 connects to c2v in - 10 = c12in2- pin of c2 connects to c2v in - 11 = c12in3- pin of c2 connects to c2v in - note 1: comparator output requires the following three conditions: c2oe = 1 , c2on = 1 and corresponding port tris bit = 0 .
pic16f882/883/884/886/887 ds41291d-page 90 preliminary ? 2007 microchip technology inc. 8.7 analog input connection considerations a simplified circuit for an analog input is shown in figure 8-6. since the analog input pins share their con- nection with a digital input, they have reverse biased esd protection diodes to v dd and v ss . the analog input, therefore, must be between v ss and v dd . if the input voltage deviates from this range by more than 0.6v in either direction, one of the diodes is forward biased and a latch-up may occur. a maximum source impedance of 10 k is recommended for the analog sources. also, any external component connected to an analog input pin, such as a capacitor or a zener diode, should have very little leakage current to minimize inaccuracies introduced. figure 8-6: analog input model note 1: when reading a port register, all pins configured as analog inputs will read as a ? 0 ?. pins configured as digital inputs will convert as an analog input, according to the input specification. 2: analog levels on any pin defined as a digital input, may cause the input buffer to consume more current than is specified. v a rs < 10k c pin 5 pf v dd v t 0.6v v t 0.6v r ic i leakage 500 na vss a in legend: c pin = input capacitance i leakage = leakage current at the pin due to various junctions r ic = interconnect resistance r s = source impedance v a = analog voltage v t = threshold voltage to adc input
? 2007 microchip technology inc. preliminary ds41291d-page 91 pic16f882/883/884/886/887 8.8 additional comparator features there are three additional comparator features: ? timer1 count enable (gate) ? synchronizing output with timer1 ? simultaneous read of comparator outputs 8.8.1 comparator c2 gating timer1 this feature can be used to time the duration or interval of analog events. clearing the t1gss bit of the cm2con1 register will enable timer1 to increment based on the output of comparator c2. this requires that timer1 is on and gating is enabled. see section 6.0 ?timer1 module with gate control? for details. it is recommended to synchronize the comparator with timer1 by setting the c2sync bit when the comparator is used as the timer1 gate source. this ensures timer1 does not miss an increment if the comparator changes during an increment. 8.8.2 synchronizing comparator c2 output to timer1 the comparator c2 output can be synchronized with timer1 by setting the c2sync bit of the cm2con1 register. when enabled, the c2 output is latched on the falling edge of the timer1 clock source. if a prescaler is used with timer1, the comparator output is latched after the prescaling function. to prevent a race condition, the comparator output is latched on the falling edge of the timer1 clock source and timer1 increments on the rising edge of its clock source. see the comparator block diagram (figures 8-2 and 8-3) and the timer1 block diagram (figure 6-1) for more information. 8.8.3 simultaneous comparator output read the mc1out and mc2out bits of the cm2con1 register are mirror copies of both comparator outputs. the ability to read both outputs simultaneously from a single register eliminates the timing skew of reading separate registers. note 1: obtaining the status of c1out or c2out by reading cm2con1 does not affect the comparator interrupt mismatch registers. register 8-3: cm2con1: comparator c2 control register 1 r-0 r-0 r/w-0 r/w-0 u-0 u-0 r/w-1 r/w-0 mc1out mc2out c1rsel c2rsel ? ? t1gss c2sync bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 mc1out: mirror copy of c1out bit bit 6 mc2out: mirror copy of c2out bit bit 5 c1rsel: comparator c1 reference select bit 1 = cvref routed to c1vref input of comparator c1 0 = absolute voltage reference (0.6) routed to c1vref input of comparator c1 (or 1.2v precision reference on parts so equipped) bit 4 c2rsel: comparator c2 reference select bit 1 = cvref routed to c2vref input of comparator c2 0 = absolute voltage reference (0.6) routed to c2vref input of comparator c2 (or 1.2v precision reference on parts so equipped) bit 3-2 unimplemented: read as ? 0 ? bit 1 t1gss: timer1 gate source select bit 1 = timer1 gate source is t1g 0 = timer1 gate source is syncc2out. bit 0 c2sync: comparator c2 output synchronization bit 1 = output is synchronous to falling edge of timer1 clock 0 = output is asynchronous
pic16f882/883/884/886/887 ds41291d-page 92 preliminary ? 2007 microchip technology inc. 8.9 comparator sr latch the sr latch module provides additional control of the comparator outputs. the module consists of a single sr latch and output multiplexers. the sr latch can be set, reset or toggled by the comparator outputs. the sr latch may also be set or reset, independent of comparator output, by control bits in the srcon control register. the sr latch output multiplexers select whether the latch outputs or the comparator outputs are directed to the i/o port logic for eventual output to a pin. 8.9.1 latch operation the latch is a set-reset latch that does not depend on a clock source. each of the set and reset inputs are active-high. each latch input is connected to a comparator output and a software controlled pulse generator. the latch can be set by c1out or the pulss bit of the srcon register. the latch can be reset by c2out or the pulsr bit of the srcon register. the latch is reset-dominant, therefore, if both set and reset inputs are high the latch will go to the reset state. both the pulss and pulsr bits are self resetting which means that a single write to either of the bits is all that is necessary to complete a latch set or reset operation. 8.9.2 latch output the sr<1:0> bits of the srcon register control the latch output multiplexers and determine four possible output configurations. in these four configurations, the cxout i/o port logic is connected to: ? c1out and c2out ? c1out and sr latch q ? c2out and sr latch q ? sr latch q and q after any reset, the default output configuration is the unlatched c1out and c2out mode. this maintains compatibility with devices that do not have the sr latch feature. the applicable tris bits of the corresponding ports must be cleared to enable t he port pin output drivers. additionally, the cxoe comp arator output enable bits of the cmxcon0 registers must be set in order to make the comparator or latch outputs available on the output pins. the latch configuration enable states are completely independent of the enable states for the comparators. figure 8-7: sr latch simplified block diagram c1sen sr0 pulss s r q q c2ren pulsr sr1 note 1: if r = 1 and s = 1 simultaneously, q = 0 , q = 1 2: pulse generator causes a 1/2 q-state (1 tosc) pulse width. 3: output shown for reference only. see i /o port pin block diagram for more detail. pulse gen ( 2 ) pulse gen ( 2 ) syncc2out (from comparator) c1out (from comparator) c2oe c2out pin (3) c1oe c1out pin (3) 0 1 mux 1 0 mux sr latch (1)
? 2007 microchip technology inc. preliminary ds41291d-page 93 pic16f882/883/884/886/887 register 8-4: srcon: sr latch control register r/w-0 r/w-0 r/w-0 r/w-0 r/s-0 r/s-0 u-0 r/w-0 sr1 (2) sr0 (2) c1sen c2ren pulss pulsr ? fvren bit 7 bit 0 legend: s = bit is set only - r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 sr1: sr latch configuration bit (2) 1 = c2out pin is the latch q output 0 = c2out pin is the c2 comparator output bit 6 sr0: sr latch configuration bits (2) 1 = c1out pin is the latch q output 0 = c1out pin is the c1 comparator output bit 5 c1sen: c1 set enable bit 1 = c1 comparator output sets sr latch 0 = c1 comparator output has no effect on sr latch bit 4 c2ren: c2 reset enable bit 1 = c2 comparator output resets sr latch 0 = c2 comparator output has no effect on sr latch bit 3 pulss: pulse the set input of the sr latch bit 1 = triggers pulse generator to set sr latch. bit is immediately reset by hardware. 0 = does not trigger pulse generator bit 2 pulsr: pulse the reset input of the sr latch bit 1 = triggers pulse generator to reset sr latch. bit is immediately reset by hardware. 0 = does not trigger pulse generator bit 1 unimplemented: read as ? 0 ? bit 0 fvren: fixed voltage reference enable bit 1 = 0.6v reference from intosc ldo is enabled 0 = 0.6v reference from intosc ldo is disabled note 1: the cxout bit in the cmxcon0 register will always refl ect the actual comparator output (not the level on the pin), regardless of the sr latch operation. 2: to enable an sr latch output to the pin, the appropriate cxoe and tris bits must be properly configured.
pic16f882/883/884/886/887 ds41291d-page 94 preliminary ? 2007 microchip technology inc. 8.10 comparator voltage reference the comparator voltage reference module provides an internally generated voltage reference for the com- parators. the following features are available: ? independent from comparator operation ? two 16-level voltage ranges ? output clamped to v ss ? ratiometric with v dd ? fixed reference (0.6v) the vrcon register (register 8-5) controls the voltage reference module shown in figure 8-8. the voltage source is selectable through both ends of the 16 connection resistor ladder network. bit vrss of the vrcon register selects either the internal or external voltage source. the pic16f883/884/886/887 allows the cv ref signal to be output to the ra2 pin of porta under certain configurations only. for more details, see figure 8-9. 8.10.1 independent operation the comparator voltage reference is independent of the comparator configuration. setting the vren bit of the vrcon register will enable the voltage reference. 8.10.2 output voltage selection the cv ref voltage reference has 2 ranges with 16 voltage levels in each range. range selection is controlled by the vrr bit of the vrcon register. the 16 levels are set with the vr<3:0> bits of the vrcon register. the cv ref output voltage is determined by the following equations: equation 8-1: cv ref output voltage the full range of v ss to v dd cannot be realized due to the construction of the module. see figure 8-8. 8.10.3 output clamped to v ss the cv ref output voltage can be set to vss with no power consumption by configuring vrcon as follows: ?vren= 0 ?vrr= 1 ?vr<3:0>= 0000 this allows the comparator to detect a zero-crossing while not consuming additional cv ref module current. 8.10.4 output ratiometric to vdd the comparator voltage reference is v dd derived and therefore, the cv ref output changes with fluctuations in v dd . the tested absolute accuracy of the comparator voltage reference can be found in section 17.0 ?electrical specifications? . 8.10.5 fixed voltage reference the fixed voltage reference is independent of v dd , with a nominal output voltage of 0.6v. this reference can be enabled by setting the fvren bit of the srcon register to ? 1 ?. this reference is always enabled when the hfintosc oscillator is active. 8.10.6 fixed voltage reference stabilization period when the fixed voltage reference module is enabled, it will require some time for the reference and its amplifier circuits to stabilize. the user program must include a small delay routine to allow the module to settle. see the electrical specifications section for the minimum delay requirement. 8.10.7 voltage reference selection multiplexers on the output of the voltage reference module enable selection of either the cv ref or fixed voltage reference for use by the comparators. setting the c1vren bit of the vrcon register enables current to flow in the cv ref voltage divider and selects the cv ref voltage for use by c1. clearing the c1vren bit selects the fixed voltage for use by c1. setting the c2vren bit of the vrcon register enables current to flow in the cv ref voltage divider and selects the cv ref voltage for use by c2. clearing the c2vren bit selects the fixed voltage for use by c2. when both the c1vren and c2vren bits are cleared, current flow in the cv ref voltage divider is disabled minimizing the power drain of the voltage reference peripheral. v rr 1 (low range): = v rr 0 (high range): = cv ref (v ladder /4) + = cv ref (vr<3:0>/24) v ladder = (vr<3:0> v ladder /32 ) v ladder v dd = or ([v ref +] - [v ref -]) or v ref +
? 2007 microchip technology inc. preliminary ds41291d-page 95 pic16f882/883/884/886/887 figure 8-8: comparator voltage reference block diagram figure 8-9: comparator and adc voltage reference block diagram v rr 8r vr<3:0> (1) analog 8rrr rr 16 stages mux fixed voltage vren cv ref reference en fvren sleep hfintosc enable 0.6v fixedref to comparators and adc module to comparators and adc module note 1: care should be taken when using v ref - with comparator. 15 0 4 v ref + v dd vrss = 0 vrss = 1 v ref - vrss = 0 vrss = 1 cv ref vroe c1rsel c2rsel v ref + vcfg0 av dd v ref - vcfg1 av ss vroe vcfg1 cv ref comparator adc av dd av ss voltage reference voltage reference vrss vrss 0 1 0 1 0 1 0 1
pic16f882/883/884/886/887 ds41291d-page 96 preliminary ? 2007 microchip technology inc. table 8-2: comparator and adc voltage reference priority ra3 ra2 comp. reference (+) comp. reference (-) adc reference (+) adc reference (-) cfg1 cfg0 vrss vroe i/o i/o av dd av ss av dd av ss 0000 i/o cv ref av dd av ss av dd av ss 0001 v ref +v ref -v ref +v ref -av dd av ss 0010 v ref +cv ref v ref +av ss av dd av ss 0011 v ref +i/o av dd av ss v ref +av ss 0100 v ref +cv ref av dd av ss v ref +av ss 0101 v ref +v ref -v ref +v ref -v ref +av ss 0110 v ref +cv ref v ref +av ss v ref +av ss 0111 i/o v ref -av dd av ss av dd v ref - 1000 i/o v ref -av dd av ss av dd v ref - 1001 v ref +v ref -v ref +v ref -av dd v ref - 1010 v ref +v ref -v ref +v ref -avddvref- 1011 v ref +v ref -av dd av ss v ref +v ref - 1100 v ref +v ref -av dd av ss v ref +v ref - 1101 v ref +v ref -v ref +v ref -v ref +v ref - 1110 v ref +v ref -v ref +v ref -v ref +v ref - 1111
? 2007 microchip technology inc. preliminary ds41291d-page 97 pic16f882/883/884/886/887 table 8-3: summary of registers associated with the comparator and voltage reference modules register 8-5: vrcon: voltage reference control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 vren vroe vrr vrss vr3 vr2 vr1 vr0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 vren: comparator c1 voltage reference enable bit 1 =cv ref circuit powered on 0 =cv ref circuit powered down bit 6 vroe: comparator c2 voltage reference enable bit 1 =cv ref voltage level is also output on the ra2/an2/v ref -/cv ref/ c2in+ pin 0 =cv ref voltage is disconnected from the ra2/an2/v ref -/cv ref/ c2in+ pin bit 5 vrr: cv ref range selection bit 1 = low range 0 = high range bit 4 vrss: comparator v ref range selection bit 1 = comparator reference source, cv rsrc = (v ref +) - (v ref -) 0 = comparator reference source, cv rsrc = v dd - v ss bit 3-0 vr<3:0>: cv ref value selection 0 vr<3:0> 15 when v rr = 1 : cv ref = (vr<3:0>/24) * v dd when v rr = 0 : cv ref = v dd /4 + (vr<3:0>/32) * v dd name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets ansel ans7 ans6 ans5 ans4 ans3 ans2 ans1 ans0 1111 1111 1111 1111 anselh ? ? ans13 ans12 ans11 ans10 ans9 ans8 --11 1111 --11 1111 cm1con0 c1on c1out c1oe c1pol ? c1r c1ch1 c1ch0 0000 -000 0000 -000 cm2con0 c2on c2out c2oe c2pol ? c2r c2ch1 c2ch0 0000 -000 0000 -000 cm2con1 mc1out mc2out c1rsel c2rsel ? ? t1gss c2sync 0000 --10 0000 --10 intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x pie2 osfie c2ie c1ie eeie bclie ulpwuie ? ccp2ie 0000 00-0 0000 00-0 pir2 osfif c2if c1if eeif bclif ulpwuif ? ccp2if 0000 00-0 0000 00-0 porta ra7 ra6 ra5 ra4 ra3 ra2 ra1 ra0 xxxx xxxx uuuu uuuu portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 xxxx xxxx uuuu uuuu srcon sr1 sr0 c1sen c2sen pulss pulsr ? fvren 0000 00-0 0000 00-0 trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 1111 1111 trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 1111 1111 1111 1111 vrcon vren vroe vrr vrss vr3 vr2 vr1 vr0 0000 0000 0000 0000 legend: x = unknown, u = unchanged, ? = unimplemented, read as ? 0 ?. shaded cells are not used for comparator.
pic16f882/883/884/886/887 ds41291d-page 98 preliminary ? 2007 microchip technology inc. notes:
? 2007 microchip technology inc. preliminary ds41291d-page 99 pic16f882/883/884/886/887 9.0 analog-to-digital converter (adc) module the analog-to-digital converter (adc) allows conversion of an analog input signal to a 10-bit binary representation of that signal. this device uses analog inputs, which are multiplexed into a single sample and hold circuit. the output of the sample and hold is connected to the input of the converter. the converter generates a 10-bit binary result via successive approximation and stores the conversion result into the adc result registers (adresl and adresh). the adc voltage reference is software selectable to either v dd or a voltage applied to the external reference pins. the adc can generate an interrupt upon completion of a conversion. this interrupt can be used to wake-up the device from sleep. figure 9-1 shows the block diagram of the adc. figure 9-1: adc block diagram an0 adc an1 an2 an4 av dd v ref + adon go/done vcfg0 = 1 vcfg0 = 0 chs<3:0> v ss an5 an6 an7 an3 an8 an9 an10 an11 an12 an13 av ss v ref - vcfg1 = 1 vcfg1 = 0 cv ref fixed ref 0000 0001 0010 0011 0100 0101 0111 0110 1000 1001 1010 1011 1100 1101 1110 1111 adresh adresl 10 10 adfm 0 = left justify 1 = right justify
pic16f882/883/884/886/887 ds41291d-page 100 preliminary ? 2007 microchip technology inc. 9.1 adc configuration when configuring and using the adc the following functions must be considered: ? port configuration ? channel selection ? adc voltage reference selection ? adc conversion clock source ? interrupt control ? results formatting 9.1.1 port configuration the adc can be used to convert both analog and digital signals. when converting analog signals, the i/o pin should be configured for analog by setting the associated tris and ansel bits. see the corresponding port section for more information. 9.1.2 channel selection the chs bits of the adcon0 register determine which channel is connected to the sample and hold circuit. when changing channels, a delay is required before starting the next conversion. refer to section 9.2 ?adc operation? for more information. 9.1.3 adc v oltage reference the vcfg bits of the adcon0 register provide independent control of the positive and negative voltage references. the positive voltage reference can be either v dd or an external voltage source. likewise, the negative voltage reference can be either v ss or an external voltage source. 9.1.4 conversion clock the source of the conversion clock is software select- able via the adcs bits of the adcon0 register. there are four possible clock options: ?f osc /2 ?f osc /8 ?f osc /32 ?f rc (dedicated internal oscillator) the time to complete one bit conversion is defined as t ad . one full 10-bit conversion requires 11 t ad periods as shown in figure 9-3. for correct conversion, the appropriate t ad specification must be met. see a/d conversion requirements in section 17.0 ?electrical specifications? for more information. table 9-1 gives examples of appropriate adc clock selections. note: analog voltages on any pin that is defined as a digital input may cause the input buffer to conduct excess current. note: unless using the f rc , any changes in the system clock frequency will change the adc clock frequency, which may adversely affect the adc result.
? 2007 microchip technology inc. preliminary ds41291d-page 101 pic16f882/883/884/886/887 table 9-1: adc clock period (t ad ) v s . device operating frequencies (vdd > 3.0v) figure 9-2: analog-to-digital conversion t ad cycles 9.1.5 interrupts the adc module allows for the ability to generate an interrupt upon completion of an analog-to-digital conversion. the adc interrupt flag is the adif bit in the pir1 register. the adc interrupt enable is the adie bit in the pie1 register. the adif bit must be cleared in software. this interrupt can be generated while the device is operating or while in sleep. if the device is in sleep, the interrupt will wake-up the device. upon waking from sleep, the next instruction following the sleep instruction is always executed. if the user is attempting to wake-up from sleep and resume in-line code execution, the global interrupt must be disabled. if the global interrupt is enabled, execution will switch to the interrupt service routine. please see section 14.3 ?interrupts? for more information. adc clock period (t ad ) device frequency (f osc ) adc clock source adcs<2:0> 20 mhz 8 mhz 4 mhz 1 mhz f osc /2 000 100 ns (2) 250 ns (2) 500 ns (2) 2.0 s f osc /8 001 400 ns (2) 1.0 s (2) 2.0 s 8.0 s (3) f osc /32 010 1.6 s4.0 s 8.0 s (3) 32.0 s (3) f rc x11 2-6 s (1,4) 2-6 s (1,4) 2-6 s (1,4) 2-6 s (1,4) legend: shaded cells are outside of recommended range. note 1: the f rc source has a typical t ad time of 4 s for v dd > 3.0v. 2: these values violate the minimum required t ad time. 3: for faster conversion times, the selection of another clock source is recommended. 4: when the device frequency is greater than 1 mhz, the f rc clock source is only recommended if the conversion will be performed during sleep. t ad 1 t ad 2 t ad 3 t ad 4 t ad 5 t ad 6 t ad 7 t ad 8 t ad 9 set go/done bit holding capacitor is disconnected from analog input (typically 100 ns) b9 b8 b7 b6 b5 b4 b3 b2 t ad 10 t ad 11 b1 b0 t cy to t ad conversion starts adresh and adresl registers are loaded, go bit is cleared, adif bit is set, holding capacitor is connected to analog input note: the adif bit is set at the completion of every conversion, regardless of whether or not the adc interrupt is enabled.
pic16f882/883/884/886/887 ds41291d-page 102 preliminary ? 2007 microchip technology inc. 9.1.6 result formatting the 10-bit a/d conversion result can be supplied in two formats, left justified or right justified. the adfm bit of the adcon0 register controls the output format. figure 9-3 shows the two output formats. figure 9-3: 10-bit a/d conversion result format 9.2 adc operation 9.2.1 starting a conversion to enable the adc module, the adon bit of the adcon0 register must be set to a ? 1 ?. setting the go/done bit of the adcon0 register to a ? 1 ? will start the analog-to-digital conversion. 9.2.2 completion of a conversion when the conversion is complete, the adc module will: ? clear the go/done bit ? set the adif flag bit ? update the adresh:adresl registers with new conversion result 9.2.3 terminating a conversion if a conversion must be terminated before completion, the go/done bit can be cleared in software. the adresh:adresl registers will not be updated with the partially complete analog-to-digital conversion sample. instead, the adresh:adresl register pair will retain the value of the previous conversion. addi- tionally, a 2 t ad delay is required before another acqui- sition can be initiated. following this delay, an input acquisition is automatically started on the selected channel. 9.2.4 adc operation during sleep the adc module can operate during sleep. this requires the adc clock source to be set to the f rc option. when the f rc clock source is selected, the adc waits one additional instruction before starting the conversion. this allows the sleep instruction to be executed, which can reduce system noise during the conversion. if the adc interrupt is enabled, the device will wake-up from sleep when the conversion completes. if the adc interrupt is disabled, the adc module is turned off after the conversion completes, although the adon bit remains set. when the adc clock source is something other than f rc , a sleep instruction causes the present conver- sion to be aborted and the adc module is turned off, although the adon bit remains set. 9.2.5 special event trigger the eccp special event trigger allows periodic adc measurements without software intervention. when this trigger occurs, the go/done bit is set by hardware and the timer1 counter resets to zero. using the special event trigger does not assure proper adc timing. it is the user?s responsibility to ensure that the adc timing requirements are met. see section 11.0 ?capture/compare/pwm modules (ccp1 and ccp2)? for more information. adresh adresl (adfm = 0 )msb lsb bit 7 bit 0 bit 7 bit 0 10-bit a/d result unimplemented: read as ? 0 ? (adfm = 1 ) msb lsb bit 7 bit 0 bit 7 bit 0 unimplemented: read as ? 0 ? 10-bit a/d result note: the go/done bit should not be set in the same instruction that turns on the adc. refer to section 9.2.6 ?a/d conversion procedure? . note: a device reset forces all registers to their reset state. thus, the adc module is turned off and any pending conversion is terminated.
? 2007 microchip technology inc. preliminary ds41291d-page 103 pic16f882/883/884/886/887 9.2.6 a/d conversion procedure this is an example procedure for using the adc to perform an analog-to-digital conversion: 1. configure port: ? disable pin output driver (see tris register) ? configure pin as analog 2. configure the adc module: ? select adc conversion clock ? configure voltage reference ? select adc input channel ? select result format ? turn on adc module 3. configure adc interrupt (optional): ? clear adc interrupt flag ? enable adc interrupt ? enable peripheral interrupt ? enable global interrupt (1) 4. wait the required acquisition time (2) . 5. start conversion by setting the go/done bit. 6. wait for adc conversion to complete by one of the following: ? polling the go/done bit ? waiting for the adc interrupt (interrupts enabled) 7. read adc result 8. clear the adc interrupt flag (required if interrupt is enabled). example 9-1: a/d conversion note 1: the global interrupt can be disabled if the user is attempting to wake-up from sleep and resume in-line code execution. 2: see section 9.3 ?a/d acquisition requirements? . ;this code block configures the adc ;for polling, vdd and vss as reference, frc clock and an0 input. ; ;conversion start & polling for completion ; are included. ; banksel adcon1 ; movlw b?10000000? ;right justify movwf adcon1 ;vdd and vss as vref banksel trisa ; bsf trisa,0 ;set ra0 to input banksel ansel ; bsf ansel,0 ;set ra0 to analog banksel adcon0 ; movlw b?11000001? ;adc frc clock, movwf adcon0 ;an0, on call sampletime ;acquisiton delay bsf adcon0,go ;start conversion btfsc adcon0,go ;is conversion done? goto $-1 ;no, test again banksel adresh ; movf adresh,w ;read upper 2 bits movwf resulthi ;store in gpr space banksel adresl ; movf adresl,w ;read lower 8 bits movwf resultlo ;store in gpr space
pic16f882/883/884/886/887 ds41291d-page 104 preliminary ? 2007 microchip technology inc. 9.2.7 adc register definitions the following registers are used to control the opera- tion of the adc. note: for ansel and anselh registers, see register 3-3 and register 3-4, respectively. register 9-1: adcon0: a/d control register 0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 adcs1 adcs0 chs3 chs2 chs1 chs0 go/done adon bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 adcs<1:0>: a/d conversion clock select bits 00 = f osc /2 01 = f osc /8 10 = f osc /32 11 = f rc (clock derived from a dedicated internal oscillator = 500 khz max) bit 5-2 chs<3:0>: analog channel select bits 0000 = an0 0001 = an1 0010 = an2 0011 = an3 0100 = an4 0101 = an5 0110 = an6 0111 = an7 1000 = an8 1001 = an9 1010 = an10 1011 = an11 1100 = an12 1101 = an13 1110 = cv ref 1111 = fixed ref (0.6 volt fixed reference) bit 1 go/done : a/d conversion status bit 1 = a/d conversion cycle in progress. setting this bit starts an a/d conversion cycle. this bit is automatically cleared by hardware when the a/d conversion has completed. 0 = a/d conversion completed/not in progress bit 0 adon: adc enable bit 1 = adc is enabled 0 = adc is disabled and consumes no operating current
? 2007 microchip technology inc. preliminary ds41291d-page 105 pic16f882/883/884/886/887 register 9-2: adcon1: a/d control register 1 r/w-0 u-0 r/w-0 r/w-0 u-0 u-0 u-0 u-0 adfm ?vcfg1vcfg0 ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 adfm: a/d conversion result format select bit 1 = right justified 0 = left justified bit 6 unimplemented: read as ? 0 ? bit 5 vcfg1: voltage reference bit 1 = v ref - pin 0 = v ss bit 4 vcfg0: voltage reference bit 1 = v ref + pin 0 = v dd bit 3-0 unimplemented: read as ? 0 ?
pic16f882/883/884/886/887 ds41291d-page 106 preliminary ? 2007 microchip technology inc. register 9-3: adresh: adc result register high (adresh) adfm = 0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x adres9 adres8 adres7 adres6 adres5 adres4 adres3 adres2 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 adres<9:2> : adc result register bits upper 8 bits of 10-bit conversion result register 9-4: adresl: adc result register low (adresl) adfm = 0 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x adres1 adres0 ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 adres<1:0> : adc result register bits lower 2 bits of 10-bit conversion result bit 5-0 reserved : do not use. register 9-5: adresh: adc result register high (adresh) adfm = 1 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x ? ? ? ? ? ? adres9 adres8 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-2 reserved : do not use. bit 1-0 adres<9:8> : adc result register bits upper 2 bits of 10-bit conversion result register 9-6: adresl: adc result register low (adresl) adfm = 1 r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x r/w-x adres7 adres6 adres5 adres4 adres3 adres2 adres1 adres0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 adres<7:0> : adc result register bits lower 8 bits of 10-bit conversion result
? 2007 microchip technology inc. preliminary ds41291d-page 107 pic16f882/883/884/886/887 9.3 a/d acquisition requirements for the adc to meet its specified accuracy, the charge holding capacitor (c hold ) must be allowed to fully charge to the input channel voltage level. the analog input model is shown in figure 9-4. the source impedance (r s ) and the internal sampling switch (r ss ) impedance directly affect the time required to charge the capacitor c hold . the sampling switch (r ss ) impedance varies over the device voltage (v dd ), see figure 9-4. the maximum recommended impedance for analog sources is 10 k . as the source impedance is decreased, the acquisition time may be decreased. after the analog input channel is selected (or changed), an a/d acquisition must be done before the conversion can be started. to calculate the minimum acquisition time, equation 9-1 may be used. this equation assumes that 1/2 lsb error is used (1024 steps for the adc). the 1/2 lsb error is the maximum error allowed for the adc to meet its specified resolution. equation 9-1: acquisition time example t acq amplifier settling time hold capacitor charging time temperature coefficient ++ = t amp t c t coff ++ = 2s t c temperature - 25c () 0.05s/c () [] ++ = t c c hold r ic r ss r s ++ () ln(1/2047) ? = 10pf 1k 7k 10k ++ () ? ln(0.0004885) = 1.37 = s t acq 2 s 1.37 s 50c- 25c () 0.05 s /c () [] ++ = 4.67 s = v applied 1e tc ? rc --------- ? ?? ?? ?? v applied 1 1 2047 ----------- - ? ?? ?? = v applied 1 1 2047 ----------- - ? ?? ?? v chold = v applied 1e t c ? rc --------- - ? ?? ?? ?? v chold = ;[1] v chold charged to within 1/2 lsb ;[2] v chold charge response to v applied ;combining [1] and [2] the value for t c can be approximated with the following equations: solving for t c : therefore: temperature 50c and external impedance of 10k 5.0v v dd = assumptions: note 1: the reference voltage (v ref ) has no effect on the equation, since it cancels itself out. 2: the charge holding capacitor (c hold ) is not discharged after each conversion. 3: the maximum recommended impedance for analog sources is 10 k . this is required to meet the pin leakage specification.
pic16f882/883/884/886/887 ds41291d-page 108 preliminary ? 2007 microchip technology inc. figure 9-4: analog input model figure 9-5: adc transfer function c pin va rs anx 5 pf v dd v t = 0.6v v t = 0.6v i leakage r ic 1k sampling switch ss rss c hold = 10 pf v ss /v ref - 6v sampling switch 5v 4v 3v 2v 567891011 (k ) v dd 500 na legend: c pin v t i leakage r ic ss c hold = input capacitance = threshold voltage = leakage current at the pin due to = interconnect resistance = sampling switch = sample/hold capacitance various junctions r ss 3ffh 3feh adc output code 3fdh 3fch 004h 003h 002h 001h 000h full-scale 3fbh 1 lsb ideal v ss /v ref - zero-scale transition v dd /v ref + transition 1 lsb ideal full-scale range analog input voltage
? 2007 microchip technology inc. preliminary ds41291d-page 109 pic16f882/883/884/886/887 table 9-2: summary of associated adc registers name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets adcon0 adcs1 adcs0 chs3 chs2 chs1 chs0 go/done adon 0000 0000 0000 0000 adcon1 adfm ?vcfg1vcfg0 ? ? ? ? 0-00 ---- -000 ---- ansel ans7 ans6 ans5 ans4 ans3 ans2 ans1 ans0 1111 1111 1111 1111 anselh ? ? ans13 ans12 ans11 ans10 ans9 ans8 --11 1111 --11 1111 adresh a/d result register high byte xxxx xxxx uuuu uuuu adresl a/d result register low byte xxxx xxxx uuuu uuuu intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x pie1 ?adie rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 pir1 ?adif rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 porta ra7 ra6 ra5 ra4 ra3 ra2 ra1 ra0 xxxx xxxx uuuu uuuu portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 xxxx xxxx uuuu uuuu porte ? ? ? ? re3 re2 re1 re0 ---- xxxx ---- uuuu trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 1111 1111 trisb trisb7 trisb6 trisb5 trisb4 tri sb3 trisb2 trisb1 trisb0 1111 1111 1111 111 trise ? ? ? ? trise3 trise2 trise1 trise0 ---- 1111 ---- 111 legend: x = unknown, u = unchanged, ? = unimplemented read as ? 0 ?. shaded cells are not used for adc module.
pic16f882/883/884/886/887 ds41291d-page 110 preliminary ? 2007 microchip technology inc. notes:
? 2007 microchip technology inc. preliminary ds41291d-page 111 pic16f882/883/884/886/887 10.0 data eeprom and flash program memory control the data eeprom and flash program memory are readable and writable during normal operation (full v dd range). these memories are not directly mapped in the register file space. instead, they are indirectly addressed through the special function registers (sfrs). there are six sfrs used to access these memories: ? eecon1 ? eecon2 ? eedat ?eedath ? eeadr ? eeadrh (bit 4 on pic16f886/pic16f887 only) when interfacing the data memory block, eedat holds the 8-bit data for read/write, and eeadr holds the address of the eedat location being accessed. these devices have 256 bytes of data eeprom with an address range from 0h to 0ffh. when accessing the program memory block of the pic16f886/pic16f887 devices, the eedat and eedath registers form a 2-byte word that holds the 14-bit data for read/write, and the eeadr and eeadrh registers form a 2-byte word that holds the 12-bit address of the eeprom location being read. the pic16f882 devices have 2k words of program eeprom with an address range from 0h to 07ffh. the pic16f883/pic16f884 devices have 4k words of program eeprom with an address range from 0h to 0fffh. the program memory allows one-word reads. the eeprom data memory allows byte read and write. a byte write automatically erases the location and writes the new data (erase before write). the write time is controlled by an on-chip timer. the write/erase voltages are generated by an on-chip charge pump rated to operate over the voltage range of the device for byte or word operations. depending on the setting of the flash program memory self write enable bits wrt<1:0> of the configuration word register 2, the device may or may not be able to write certain blocks of the program memory. however, reads from the program memory are allowed. when the device is code-protected, the cpu may continue to read and write the data eeprom memory and flash program memory. when code-protected, the device programmer can no longer access data or program memory. 10.1 eeadr and eeadrh registers the eeadr and eeadrh registers can address up to a maximum of 256 bytes of data eeprom or up to a maximum of 8k words of program eeprom. when selecting a program address value, the msb of the address is written to the eeadrh register and the lsb is written to the eeadr register. when selecting a data address value, only the lsb of the address is written to the eeadr register. 10.1.1 eecon1 and eecon2 registers eecon1 is the control register for ee memory accesses. control bit eepgd determines if the access will be a pro- gram or data memory access. when clear, as it is when reset, any subsequent operations will operate on the data memory. when set, any subsequent operations will oper- ate on the program memory. program memory can only be read. control bits rd and wr initiate read and write, respectively. these bits cannot be cleared, only set, in software. they are cleared in hardware at completion of the read or write operation. the inability to clear the wr bit in software prevents the accidental, premature termination of a write operation. the wren bit, when set, will allow a write operation to data eeprom. on power-up, the wren bit is clear. the wrerr bit is set when a write operation is interrupted by a mclr or a wdt time-out reset during normal operation. in these situations, following reset, the user can check the wrerr bit and rewrite the location. interrupt flag bit eeif of the pir2 register is set when write is complete. it must be cleared in the software. eecon2 is not a physical register. reading eecon2 will read all ? 0 ?s. the eecon2 register is used exclusively in the data eeprom write sequence.
pic16f882/883/884/886/887 ds41291d-page 112 preliminary ? 2007 microchip technology inc. register 10-1: eedat: eeprom data register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 eedat7 eedat6 eedat5 eedat4 eedat3 eedat2 eedat1 eedat0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 eedat<7:0> : 8 least significant address bits to write to or read from data eeprom or read from program memory register 10-2: eeadr: eeprom address register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 eeadr7 eeadr6 eeadr5 eeadr4 eeadr3 eeadr2 eeadr1 eeadr0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-0 eeadr<7:0> : 8 least significant address bits for eeprom read/write operation (1) or read from program memory register 10-3: eedath: eeprom data high byte register u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? eedath5 eedath4 eedath3 eedath2 eedath1 eedath0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-0 eedath<5:0> : 6 most significant data bits from program memory register 10-4: eeadrh: eeprom address high byte register u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? eeadrh4 (1) eeadrh3 eeadrh2 eeadrh1 eeadrh0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-0 eeadrh<4:0> : specifies the 4 most significant address bits or high bits for program memory reads note 1: pic16f886/pic16f887 only.
? 2007 microchip technology inc. preliminary ds41291d-page 113 pic16f882/883/884/886/887 register 10-5: eecon1: eeprom control register r/w-x u-0 u-0 u-0 r/w-x r/w-0 r/s-0 r/s-0 eepgd ? ? ? wrerr wren wr rd bit 7 bit 0 legend: s = bit can only be set r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 eepgd: program/data eeprom select bit 1 = accesses program memory 0 = accesses data memory bit 6-4 unimplemented: read as ? 0 ? bit 3 wrerr: eeprom error flag bit 1 = a write operation is prematurely terminated (any mclr reset, any wdt reset during normal operation or bor reset) 0 = the write operation completed bit 2 wren: eeprom write enable bit 1 = allows write cycles 0 = inhibits write to the data eeprom bit 1 wr: write control bit 1 = initiates a write cycle (the bit is cleared by hardware once write is complete. the wr bit can only be set, not cleared, in software.) 0 = write cycle to the data eeprom is complete bit 0 rd: read control bit 1 = initiates a memory read (the rd is cleared in hardware and can only be set, not cleared, in software.) 0 = does not initiate a memory read
pic16f882/883/884/886/887 ds41291d-page 114 preliminary ? 2007 microchip technology inc. 10.1.2 reading the data eeprom memory to read a data memory location, the user must write the address to the eeadr register, clear the eepgd control bit of the eecon1 register, and then set control bit rd. the data is available at the very next cycle, in the eedat register; therefore, it can be read in the next instruction. eedat will hold this value until another read or until it is written to by the user (during a write operation). example 10-1: data eeprom read 10.1.3 writing to the data eeprom memory to write an eeprom data location, the user must first write the address to the eeadr register and the data to the eedat register. then the user must follow a specific sequence to initiate the write for each byte. the write will not initiate if the above sequence is not followed exactly (write 55h to eecon2, write aah to eecon2, then set wr bit) for each byte. interrupts should be disabled during this code segment. additionally, the wren bit in eecon1 must be set to enable write. this mechanism prevents accidental writes to data eeprom due to errant (unexpected) code execution (i.e., lost programs). the user should keep the wren bit clear at all times, except when updating eeprom. the wren bit is not cleared by hardware. after a write sequence has been initiated, clearing the wren bit will not affect this write cycle. the wr bit will be inhibited from being set unless the wren bit is set. at the completion of the write cycle, the wr bit is cleared in hardware and the ee write complete interrupt flag bit (eeif) is set. the user can either enable this interrupt or poll this bit. eeif must be cleared by software. example 10-2: data eeprom write banksel eeadr ; movlw data_ee_addr ; movwf eeadr ;data memory ;address to read banksel eecon1 ; bcf eecon1, eepgd ;point to data memory bsf eecon1, rd ;ee read banksel eedat ; movf eedat, w ;w = eedat bcf status, rp1 ;bank 0 banksel eeadr ; movlw data_ee_addr ; movwf eeadr ;data memory address to write movlw data_ee_data ; movwf eedat ;data memory value to write banksel eecon1 ; bcf eecon1, eepgd ;point to data memory bsf eecon1, wren ;enable writes bcf intcon, gie ;disable ints. btfsc intcon, gie ;see an576 goto $-2 movlw 55h ; movwf eecon2 ;write 55h movlw aah ; movwf eecon2 ;write aah bsf eecon1, wr ;set wr bit to begin write bsf intcon, gie ;enable ints. sleep ;wait for interrupt to signal write complete bcf eecon1, wren ;disable writes bcf status, rp0 ;bank 0 bcf status, rp1 required sequence
? 2007 microchip technology inc. preliminary ds41291d-page 115 pic16f882/883/884/886/887 10.1.4 reading the flash program memory to read a program memory location, the user must write the least and most significant address bits to the eeadr and eeadrh registers, set the eepgd con- trol bit of the eecon1 register, and then set control bit rd. once the read control bit is set, the program mem- ory flash controller will use the second instruction cycle to read the data. this causes the second instruc- tion immediately following the ? bsf eecon1,rd ? instruction to be ignored. the data is available in the very next cycle, in the eedat and eedath registers; therefore, it can be read as two bytes in the following instructions. eedat and eedath registers will hold this value until another read or until it is written to by the user. example 10-3: flash program read note 1: the two instructions following a program memory read are required to be nop s. this prevents the user from executing a two-cycle instruction on the next instruction after the rd bit is set. 2: if the wr bit is set when eepgd = 1 , it will be immediately reset to ? 0 ? and no operation will take place. banksel eeadr ; movlw ms_prog_ee_addr ; movwf eeadrh ;ms byte of program address to read movlw ls_prog_ee_addr ; movwf eeadr ;ls byte of program address to read banksel eecon1 ; bsf eecon1, eepgd ;point to program memory bsf eecon1, rd ;ee read ; ;first instruction after bsf eecon1,rd executes normally nop nop ;any instructions here are ignored as program ;memory is read in second cycle after bsf eecon1,rd ; banksel eedat ; movf eedat, w ;w = ls byte of program memory movwf lowpmbyte ; movf eedath, w ;w = ms byte of program eedat movwf highpmbyte ; bcf status, rp1 ;bank 0 required sequence
pic16f882/883/884/886/887 ds41291d-page 116 preliminary ? 2007 microchip technology inc. figure 10-1: flash program me mory read cycle execution q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 bsf eecon1,rd executed here instr(pc + 1) executed here forced nop executed here pc pc + 1 eeadrh,eeadr pc+3 pc + 5 flash addr rd bit eedath,eedat pc + 3 pc + 4 instr (pc + 1) instr(pc - 1) executed here instr(pc + 3) executed here instr(pc + 4) executed here flash data eedath eedat register eerhlt instr (pc) instr (pc + 3) instr (pc + 4)
? 2007 microchip technology inc. preliminary ds41291d-page 117 pic16f882/883/884/886/887 10.2 writing to flash program memory flash program memory may only be written to if the destination address is in a segment of memory that is not write-protected, as defined in bits wrt<1:0> of the configuration word register 2. flash program memory must be written in eight-word blocks (four-word blocks for 4k memory devices). see figures 10-2 and 10-3 for more details. a block consists of eight words with sequential addresses, with a lower boundary defined by an address, where eeadr<2:0> = 000 . all block writes to program memory are done as 16-word erase by eight-word write operations. the write operation is edge-aligned and cannot occur across boundaries. to write program data, it must first be loaded into the buffer registers (see figure 10-2). this is accomplished by first writing the destination address to eeadr and eeadrh and then writing the data to eedata and eedath. after the address and data have been set up, then the following sequence of events must be executed: 1. set the eepgd control bit of the eecon1 register. 2. write 55h, then aah, to eecon2 (flash programming sequence). 3. set the wr control bit of the eecon1 register. all eight buffer register locations should be written to with correct data. if less than eight words are being writ- ten to in the block of eight words, then a read from the program memory location(s) not being written to must be performed. this takes the data from the program location(s) not being written and loads it into the eedata and eedath registers. then the sequence of events to transfer data to the buffer registers must be executed. to transfer data from the buffer registers to the program memory, the eeadr and eeadrh must point to the last location in the eight-word block (eeadr<2:0> = 111 ). then the following sequence of events must be executed: 1. set the eepgd control bit of the eecon1 register. 2. write 55h, then aah, to eecon2 (flash programming sequence). 3. set control bit wr of the eecon1 register to begin the write operation. the user must follow the same specific sequence to initiate the write for each word in the program block, writing each program word in sequence ( 000 , 001 , 010 , 011 , 100 , 101 , 110 , 111 ). when the write is performed on the last word (eeadr<2:0> = 111 ), a block of sixteen words is automatically erased and the content of the eight word buffer registers are written into the program memory. after the ? bsf eecon1,wr ? instruction, the processor requires two cycles to set up the erase/write operation. the user must place two nop instructions after the wr bit is set. since data is being written to buffer registers, the writing of the first seven words of the block appears to occur immediately. the processor will halt internal operations for the typical 4 ms, only during the cycle in which the erase takes place (i.e., the last word of the sixteen-word block erase). this is not sleep mode as the clocks and peripherals will continue to run. after the eight-word write cycle, the processor will resume oper- ation with the third instruction after the eecon1 write instruction. the above sequence must be repeated for the higher eight words.
pic16f882/883/884/886/887 ds41291d-page 118 preliminary ? 2007 microchip technology inc. figure 10-2: block writ es to 2k and 4k flash program memory figure 10-3: block writes to 8k flash program memory 14 14 14 14 program memory buffer register eeadr<1:0> = 00 buffer register eeadr<1:0> = 01 buffer register eeadr<1:0> = 10 buffer register eeadr<1:0> = 11 eedata eedath 75 07 0 6 8 first word of block to be written sixteen words of to flash automatically after this word is written are transferred flash are erased, then four buffers 14 14 14 14 program memory buffer register eeadr<2:0> = 000 buffer register eeadr<2:0> = 001 buffer register eeadr<2:0> = 010 buffer register eeadr<2:0> = 111 eedata eedath 75 07 0 6 8 first word of block to be written sixteen words of to flash automatically after this word is written are transferred flash are erased, then eight buffer s
? 2007 microchip technology inc. preliminary ds41291d-page 119 pic16f882/883/884/886/887 an example of the complete eight-word write sequence is shown in example 10-4. the initial address is loaded into the eeadrh and eeadr register pair; the eight words of data are loaded using indirect addressing. example 10-4: writing to flash program memory ; this write routine assumes the following: ; ; 1. a valid starting address (the least significant bits = ?00?)is loaded in addrh:addrl ; 2. the 8 bytes of data are loaded, starting at the address in dataddr ; 3. addrh, addrl and dataddr are all located in shared data memory 0x70 - 0x7f ; bsf status,rp1 ; bcf status,rp0 ; bank 2 movf addrh,w ; load initial address movwf eeadrh ; movf addrl,w ; movwf eeadr ; movf dataaddr,w ; load initial data address movwf fsr ; loop movf indf,w ; load first data byte into lower movwf eedata ; incf fsr,f ; next byte movf indf,w ; load second data byte into upper movwf eedath ; incf fsr,f ; bsf status,rp0 ; bank 3 bsf eecon1,eepgd ; point to program memory bsf eecon1,wren ; enable writes bcf intcon,gie ; disable interrupts (if using) btfsc intcon,gie ; see an576 goto 1-2 movlw 55h ; start of required write sequence: movwf eecon2 ; write 55h movlw aah ; movwf eecon2 ; write aah bsf eecon1,wr ; set wr bit to begin write nop ; any instructions here are ignored as processor ; halts to begin write sequence nop ; processor will stop here and wait for write complete ; after write processor continues with 3rd instruction bcf eecon1,wren ; disable writes bsf intcon,gie ; enable interrupts (if using) bcf status,rp0 ; bank 2 incf eeadr,f ; increment address movf eeadr,w ; check if lower two bits of address are ?00? andlw 0x07 ; indicates when four words have been programmed xorlw 0x07 ; btfsc status,z ; exit if more than eight words, goto loop ; continue if less than eight words required sequence
pic16f882/883/884/886/887 ds41291d-page 120 preliminary ? 2007 microchip technology inc. 10.3 write verify depending on the application, good programming practice may dictate that the value written to the data eeprom should be verified (see example 10-5) to the desired value to be written. example 10-5: write verify 10.3.1 using the data eeprom the data eeprom is a high-endurance, byte addressable array that has been optimized for the storage of frequently changing information (e.g., program variables or other data that are updated often). when variables in one section change frequently, while variables in another section do not change, it is possible to exceed the total number of write cycles to the eeprom (specification d124) without exceeding the total number of write cycles to a single byte (specifications d120 and d120a). if this is the case, then a refresh of the array must be performed. for this reason, variables that change infrequently (such as constants, ids, calibration, etc.) should be stored in flash program memory. 10.4 protection against spurious write there are conditions when the user may not want to write to the data eeprom memory. to protect against spurious eeprom writes, various mechanisms have been built in. on power-up, wren is cleared. also, the power-up timer (64 ms duration) prevents eeprom write. the write initiate sequence and the wren bit together help prevent an accidental write during: ? brown-out ?power glitch ? software malfunction 10.5 data eeprom operation during code-protect data memory can be code-protected by programming the cpd bit in the configuration word register 1 (register 14-1) to ? 0 ?. when the data memory is code-protected, only the cpu is able to read and write data to the data eeprom. it is recommended to code-protect the pro- gram memory when code-protecting data memory. this prevents anyone from programming zeroes over the existing code (which will execute as nop s) to reach an added routine, programmed in unused program memory, which outputs the contents of data memory. programming unused locations in program memory to ? 0 ? will also help prevent data memory code protection from becoming breached. banksel eedat ; movf eedat, w ;eedat not changed ;from previous write banksel eecon1 ; bsf eecon1, rd ;yes, read the ;value written banksel eedat ; xorwf eedat, w ; btfss status, z ;is data the same goto write_err ;no, handle error : ;yes, continue bcf status, rp1 ;bank 0
? 2007 microchip technology inc. preliminary ds41291d-page 121 pic16f882/883/884/886/887 table 10-1: summary of registers associated with data eeprom name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets eecon1 eepgd ? ? ? wrerr wren wr rd x--- x000 0--- q000 eecon2 eeprom control register 2 (not a physical register) ---- ---- ---- ---- eeadr eeadr7 eeadr6 eeadr5 eeadr4 eeadr3 eeadr2 eeadr1 eeadr0 0000 0000 0000 0000 eeadrh ? ? ? eeadrh4 (1) eeadrh3 eeadrh2 eeadrh1 eeadrh0 ---0 0000 ---0 0000 eedat eedat7 eedat6 eedat5 eedat4 eedat3 eedat2 eedat1 eedat0 0000 0000 0000 0000 eedath ? ? eedath5 eedath4 eedath3 eedath2 eedath1 eedath0 --00 0000 --00 0000 intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x pie2 osfie c2ie c1ie eeie bclie ulpwuie ? ccp2ie 0000 00-0 0000 00-0 pir2 osfif c2if c1if eeif bclif ulpwuif ? ccp2if 0000 00-0 0000 00-0 legend: x = unknown, u = unchanged, ? = unimplemented read as ? 0 ?, q = value depends upon condition. shaded cells are not used by data eeprom module. note 1: pic16f886/pic16f887 only.
pic16f882/883/884/886/887 ds41291d-page 122 preliminary ? 2007 microchip technology inc. notes:
? 2007 microchip technology inc. preliminary ds41291d-page 123 pic16f882/883/884/886/887 11.0 capture/compare/pwm modules (ccp1 and ccp2) this device contains one enhanced capture/compare/ pwm (ccp1) and capture/compare/pwm module (ccp2). the ccp1 and ccp2 modules are identical in operation, with the exception of the enhanced pwm features available on ccp1 only. see section 11.6 ?pwm (enhanced mode)? for more information. note: ccprx and ccpx throughout this document refer to ccpr1 or ccpr2 and ccp1 or ccp2, respectively.
pic16f882/883/884/886/887 ds41291d-page 124 preliminary ? 2007 microchip technology inc. 11.1 enhanced capture/compare/pwm (ccp1) the enhanced capture/compare/pwm module is a peripheral which allows the user to time and control different events. in capture mode, the peripheral allows the timing of the duration of an event. the compare mode allows the user to trigger an external event when a predetermined amount of time has expired. the pwm mode can generate a pulse-width modulated signal of varying frequency and duty cycle. table 11-1 shows the timer resources required by the eccp module. table 11-1: eccp mode ? timer resources required eccp mode timer resource capture timer1 compare timer1 pwm timer2 register 11-1: ccp1con: enhanced ccp1 control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 p1m1 p1m0 dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 p1m<1:0>: pwm output configuration bits i f ccp1m<3:2> = 00 , 01 , 10 : xx = p1a assigned as capture/compare input; p1b, p1c, p1d assigned as port pins if ccp1m<3:2> = 11 : 00 = single output; p1a modulated; p1b, p1c, p1d assigned as port pins 01 = full-bridge output forward; p1d modulated; p1a active; p1b, p1c inactive 10 = half-bridge output; p1a, p1b modulated with dead-band control; p1c, p1d assigned as port pins 11 = full-bridge output reverse; p1b modulated; p1c active; p1a, p1d inactive bit 5-4 dc1b<1:0>: pwm duty cycle least significant bits capture mode: unused. compare mode: unused. pwm mode: these bits are the two lsbs of the pwm duty cycle. the eight msbs are found in ccpr1l. bit 3-0 ccp1m<3:0>: eccp mode select bits 0000 = capture/compare/pwm off (resets eccp module) 0001 = unused (reserved) 0010 = compare mode, toggle output on match (ccp1if bit is set) 0011 = unused (reserved) 0100 = capture mode, every falling edge 0101 = capture mode, every rising edge 0110 = capture mode, every 4th rising edge 0111 = capture mode, every 16th rising edge 1000 = compare mode, set output on match (ccp1if bit is set) 1001 = compare mode, clear output on match (ccp1if bit is set) 1010 = compare mode, generate software interrupt on match (ccp1if bit is set, ccp1 pin is unaffected) 1011 = compare mode, trigger special event (ccp 1if bit is set; ccp1 resets tmr1 or tmr2 1100 = pwm mode; p1a, p1c active-high; p1b, p1d active-high 1101 = pwm mode; p1a, p1c active-high; p1b, p1d active-low 1110 = pwm mode; p1a, p1c active-low; p1b, p1d active-high 1111 = pwm mode; p1a, p1c active-low; p1b, p1d active-low
? 2007 microchip technology inc. preliminary ds41291d-page 125 pic16f882/883/884/886/887 11.2 capture/compare/pwm (ccp2) the capture/compare/pwm module is a peripheral which allows the user to time and control different events. in capture mode, the peripheral allows the timing of the duration of an event. the compare mode allows the user to trigger an external event when a predetermined amount of time has expired. the pwm mode can generate a pulse-width modulated signal of varying frequency and duty cycle. the timer resources used by the module are shown in table 11-2. additional information on ccp modules is available in the application note an594, ?using the ccp modules? (ds00594). table 11-2: ccp mode ? timer resources required ccp mode timer resource capture timer1 compare timer1 pwm timer2 register 11-2: ccp2con: ccp2 control register u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? dc2b1 dc2b0 ccp2m3 ccp2m2 ccp2m1 ccp2m0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-4 dc2b<1:0>: pwm duty cycle least significant bits capture mode: unused. compare mode: unused. pwm mode: these bits are the two lsbs of the pwm duty cycle. the eight msbs are found in ccpr2l. bit 3-0 ccp2m<3:0>: ccp2 mode select bits 0000 = capture/compare/pwm off (resets ccp2 module) 0001 = unused (reserved) 0010 = unused (reserved) 0011 = unused (reserved) 0100 = capture mode, every falling edge 0101 = capture mode, every rising edge 0110 = capture mode, every 4th rising edge 0111 = capture mode, every 16th rising edge 1000 = compare mode, set output on match (ccp2if bit is set) 1001 = compare mode, clear output on match (ccp2if bit is set) 1010 = compare mode, generate software interrupt on match (ccp2if bit is set, ccp2 pin is unaffected) 1011 = compare mode, trigger special event (ccp2if bit is set, tmr1 is reset and a/d conversion is started if the adc module is enabled. ccp2 pin is unaffected.) 11xx = pwm mode.
pic16f882/883/884/886/887 ds41291d-page 126 preliminary ? 2007 microchip technology inc. 11.3 capture mode in capture mode, the ccprxh, ccprxl register pair captures the 16-bit value of the tmr1 register when an event occurs on pin ccpx. an event is defined as one of the following and is configured by the ccp1m<3:0> bits of the ccp1con register: ? every falling edge ? every rising edge ? every 4th rising edge ? every 16th rising edge when a capture is made, the interrupt request flag bit ccpxif of the pirx register is set. the interrupt flag must be cleared in software. if another capture occurs before the value in the ccprxh, ccprxl register pair is read, the old captured value is overwritten by the new captured value (see figure 11-1). 11.3.1 ccp pin configuration in capture mode, the ccpx pin should be configured as an input by setting the associated tris control bit. figure 11-1: capture mode operation block diagram 11.3.2 timer1 mode selection timer1 must be running in timer mode or synchronized counter mode for the ccp module to use the capture feature. in asynchronous counter mode, the capture operation may not work. 11.3.3 software interrupt when the capture mode is changed, a false capture interrupt may be generated. the user should keep the ccpxie interrupt enable bit of the piex register clear to avoid false interrupts. additionally, the user should clear the ccpxif interrupt flag bit of the pirx register following any change in operating mode. 11.3.4 ccp prescaler there are four prescaler settings specified by the ccpxm<3:0> bits of the ccpxcon register. whenever the ccp module is turned off, or the ccp module is not in capture mode, the prescaler counter is cleared. any reset will clear the prescaler counter. switching from one capture prescaler to another does not clear the prescaler and may generate a false interrupt. to avoid this unexpected operation, turn the module off by clearing the ccpxcon register before changing the prescaler (see example 11-1). example 11-1: changing between capture prescalers note: if the ccpx pin is configured as an output, a write to the port can cause a capture condition. ccprxh ccprxl tmr1h tmr1l set flag bit ccpxif (pirx register) capture enable ccpxcon<3:0> prescaler 1, 4, 16 and edge detect pin ccpx system clock (f osc ) banksel ccp1con ;set bank bits to point ;to ccp1con clrf ccp1con ;turn ccp module off movlw new_capt_ps ;load the w reg with ; the new prescaler ; move value and ccp on movwf ccp1con ;load ccp1con with this ; value
? 2007 microchip technology inc. preliminary ds41291d-page 127 pic16f882/883/884/886/887 11.4 compare mode in compare mode, the 16-bit ccprx register value is constantly compared against the tmr1 register pair value. when a match occurs, the ccpx module may: ? toggle the ccpx output ? set the ccpx output ? clear the ccpx output ? generate a special event trigger ? generate a software interrupt the action on the pin is based on the value of the ccpxm<3:0> control bits of the ccpx1con register. all compare modes can generate an interrupt. figure 11-2: compare mode operation block diagram 11.4.1 ccp pin configuration the user must configure the ccpx pin as an output by clearing the associated tris bit. 11.4.2 timer1 mode selection in compare mode, timer1 must be running in either timer mode or synchronized counter mode. the compare operation may not work in asynchronous counter mode. 11.4.3 software interrupt mode when generate software interrupt mode is chosen (ccpxm<3:0> = 1010 ), the ccpx module does not assert control of the ccpx pin (see the ccp1con register). 11.4.4 special event trigger when special event trigger mode is chosen (ccpxm<3:0> = 1011 ), the ccpx module does the following: ? resets timer1 ? starts an adc conversion if adc is enabled the ccpx module does not assert control of the ccpx pin in this mode (see the ccpxcon register). the special event trigger output of the ccp occurs immediately upon a match between the tmr1h, tmr1l register pair and the ccprxh, ccprxl register pair. the tmr1h, tmr1l register pair is not reset until the next rising edge of the timer1 clock. this allows the ccprxh, ccprxl register pair to effectively provide a 16-bit programmable period register for timer1. note: clearing the ccp1con register will force the ccpx compare output latch to the default low level. this is not the port i/o data latch. ccprxh ccprxl tmr1h tmr1l comparator qs r output logic special event trigger set ccpxif interrupt flag (pirx) match tris ccpxcon<3:0> mode select output enable pin special event trigger will: ? clear tmr1h and tmr1l registers. ? not set interrupt flag bit tmr1if of the pir1 register. ? set the go/done bit to start the adc conversion. ccpx 4 note 1: the special event trigger from the ccp module does not set interrupt flag bit tmrxif of the pir1 register. 2: removing the match condition by changing the contents of the ccprxh and ccprxl register pair, between the clock edge that generates the special event trigger and the clock edge that generates the timer1 reset, will preclude the reset from occurring.
pic16f882/883/884/886/887 ds41291d-page 128 preliminary ? 2007 microchip technology inc. 11.5 pwm mode the pwm mode generates a pulse-width modulated signal on the ccpx pin. the duty cycle, period and resolution are determined by the following registers: ?pr2 ?t2con ? ccprxl ? ccpxcon in pulse-width modulation (pwm) mode, the ccp module produces up to a 10-bit resolution pwm output on the ccpx pin. since the ccpx pin is multiplexed with the port data latch, the tris for that pin must be cleared to enable the ccpx pin output driver. figure 11-3 shows a simplified block diagram of pwm operation. figure 11-4 shows a typical waveform of the pwm signal. for a step-by-step procedure on how to set up the ccp module for pwm operation, see section 11.5.7 ?setup for pwm operation? . figure 11-3: simplified pwm block diagram the pwm output (figure 11-4) has a time base (period) and a time that the output stays high (duty cycle). figure 11-4: ccp pwm output note: clearing the ccpxcon register will relinquish ccpx control of the ccpx pin. ccprxl ccprxh (2) (slave) comparator tmr2 pr2 (1) rq s duty cycle registers ccpxcon<5:4> clear timer2, toggle ccpx pin and latch duty cycle note 1: the 8-bit timer tmr2 register is concatenated with the 2-bit internal system clock (f osc ), or 2 bits of the prescaler, to create the 10-bit time base. 2: in pwm mode, ccprxh is a read-only register . tris ccpx comparator period pulse width tmr2 = 0 tmr2 = ccprxl:ccpxcon<5:4> tmr2 = pr2
? 2007 microchip technology inc. preliminary ds41291d-page 129 pic16f882/883/884/886/887 11.5.1 pwm period the pwm period is specified by the pr2 register of timer2. the pwm period can be calculated using the formula of equation 11-1. equation 11-1: pwm period when tmr2 is equal to pr2, the following three events occur on the next increment cycle: ? tmr2 is cleared ? the ccpx pin is set. (exception: if the pwm duty cycle = 0%, the pin will not be set.) ? the pwm duty cycle is latched from ccprxl into ccprxh. 11.5.2 pwm duty cycle the pwm duty cycle is specified by writing a 10-bit value to multiple registers: ccprxl register and dcxb<1:0> bits of the ccpxcon register. the ccprxl contains the eight msbs and the dcxb<1:0> bits of the ccpxcon register contain the two lsbs. ccprxl and dcxb<1:0> bits of the ccpxcon register can be written to at any time. the duty cycle value is not latched into ccprxh until after the period completes (i.e., a match between pr2 and tmr2 registers occurs). while using the pwm, the ccprxh register is read-only. equation 11-2 is used to calculate the pwm pulse width. equation 11-3 is used to calculate the pwm duty cycle ratio. equation 11-2: pulse width equation 11-3: duty cycle ratio the ccprxh register and a 2-bit internal latch are used to double buffer the pwm duty cycle. this double buffering is essential for glitchless pwm operation. the 8-bit timer tmr2 register is concatenated with either the 2-bit internal system clock (f osc ), or 2 bits of the prescaler, to create the 10-bit time base. the system clock is used if the timer2 prescaler is set to 1:1. when the 10-bit time base matches the ccprxh and 2-bit latch, then the ccpx pin is cleared (see figure 11-3). note: the timer2 postscaler (see section 7.1 ?timer2 operation? ) is not used in the determination of the pwm frequency. pwm period pr2 () 1 + [] 4t osc ? ? ? = (tmr2 prescale value) pulse width ccprxl:ccpxcon<5:4> () ? = t osc ? (tmr2 prescale value) duty cycle ratio ccprxl:ccpxcon<5:4> () 4pr2 1 + () ---------------------------------------------------------------------- - =
pic16f882/883/884/886/887 ds41291d-page 130 preliminary ? 2007 microchip technology inc. 11.5.3 pwm resolution the resolution determines the number of available duty cycles for a given period. for example, a 10-bit resolution will result in 1024 discrete duty cycles, whereas an 8-bit resolution will result in 256 discrete duty cycles. the maximum pwm resolution is 10 bits when pr2 is 255. the resolution is a function of the pr2 register value as shown by equation 11-4. equation 11-4: pwm resolution table 11-3: example pwm frequencies and resolutions (f osc = 20 mhz) table 11-4: example pwm frequencies and resolutions (f osc = 8 mhz) note: if the pulse width value is greater than the period the assigned pwm pin(s) will remain unchanged. resolution 4pr2 1 + () [] log 2 () log ----------------------------------------- - bits = pwm frequency 1.22 khz 4.88 khz 19.53 khz 78.12 khz 156.3 khz 208.3 khz timer prescale (1, 4, 16) 16 4 1 1 1 1 pr2 value 0xff 0xff 0xff 0x3f 0x1f 0x17 maximum resolution (bits) 10 10 10 8 7 6.6 pwm frequency 1.22 khz 4.90 khz 19.61 khz 76.92 khz 153.85 khz 200.0 khz timer prescale (1, 4, 16) 16 4 1 1 1 1 pr2 value 0x65 0x65 0x65 0x19 0x0c 0x09 maximum resolution (bits) 8 8 8 6 5 5
? 2007 microchip technology inc. preliminary ds41291d-page 131 pic16f882/883/884/886/887 11.5.4 operation in sleep mode in sleep mode, the tmr2 register will not increment and the state of the module will not change. if the ccpx pin is driving a value, it will continue to drive that value. when the device wakes up, tmr2 will continue from its previous state. 11.5.5 changes in system clock frequency the pwm frequency is derived from the system clock frequency. any changes in the system clock frequency will result in changes to the pwm frequency. see section 4.0 ?oscillator module (with fail-safe clock monitor)? for additional details. 11.5.6 effects of reset any reset will force all ports to input mode and the ccp registers to their reset states. 11.5.7 setup for pwm operation the following steps should be taken when configuring the ccp module for pwm operation: 1. disable the pwm pin (ccpx) output drivers as an input by setting the associated tris bit. 2. set the pwm period by loading the pr2 register. 3. configure the ccp module for the pwm mode by loading the ccpxcon register with the appropriate values. 4. set the pwm duty cycle by loading the ccprxl register and dcxb<1:0> bits of the ccpxcon register. 5. configure and start timer2: ? clear the tmr2if interrupt flag bit of the pir1 register. ? set the timer2 prescale value by loading the t2ckps bits of the t2con register. ? enable timer2 by setting the tmr2on bit of the t2con register. 6. enable pwm output after a new pwm cycle has started: ? wait until timer2 overflows (tmr2if bit of the pir1 register is set). ? enable the ccpx pin output driver by clearing the associated tris bit.
pic16f882/883/884/886/887 ds41291d-page 132 preliminary ? 2007 microchip technology inc. 11.6 pwm (enhanced mode) the enhanced pwm mode can generate a pwm signal on up to four different output pins with up to 10-bits of resolution. it can do this through four different pwm output modes: ? single pwm ? half-bridge pwm ? full-bridge pwm, forward mode ? full-bridge pwm, reverse mode to select an enhanced pwm mode, the p1m bits of the ccp1con register must be set appropriately. the pwm outputs are multiplexed with i/o pins and are designated p1a, p1b, p1c and p1d. the polarity of the pwm pins is configurable and is selected by setting the ccp1m bits in the ccp1con register appropriately. table 11-5 shows the pin assignments for each enhanced pwm mode. figure 11-5 shows an example of a simplified block diagram of the enhanced pwm module. figure 11-5: example simplified block diagram of the enhanced pwm mode table 11-5: example pin assignments for various pwm enhanced modes note: the pwm enhanced mode is available on the enhanced capture/compare/pwm module (ccp1) only. note: to prevent the generation of an incomplete waveform when the pwm is first enabled, the eccp module waits until the start of a new pwm period before generating a pwm signal. ccpr1l ccpr1h (slave) comparator tmr2 comparator pr2 (1) rq s duty cycle registers dc1b<1:0> clear timer2, toggle pwm pin and latch duty cycle note 1: the 8-bit timer tmr2 register is concatenated with the 2-bit internal q clock, or 2 bits of the prescaler to create the 10-bit time base. trisn ccp1/p1a trisn p1b trisn p1c trisn p1d output controller p1m<1:0> 2 ccp1m<3:0> 4 pwm1con ccp1/p1a p1b p1c p1d note 1: the tris register value for each pwm output must be configured appropriately. 2: clearing the ccpxcon register will relinquish eccp control of all pwm output pins. 3: any pin not used by an enhanced pwm mode is available for alternate pin functions. eccp mode p1m<1:0> ccp1/p1a p1b p1c p1d single 00 yes (1) yes (1) yes (1) yes (1) half-bridge 10 yes yes no no full-bridge, forward 01 yes yes yes yes full-bridge, reverse 11 yes yes yes yes note 1: pulse steering enables outputs in single mode.
? 2007 microchip technology inc. preliminary ds41291d-page 133 pic16f882/883/884/886/887 figure 11-6: example pwm (enhanced mode) output relationships (active-high state) 0 period 00 10 01 11 signal pr2+1 p1m<1:0> p1a modulated p1a modulated p1b modulated p1a active p1b inactive p1c inactive p1d modulated p1a inactive p1b modulated p1c active p1d inactive pulse width (single output) (half-bridge) (full-bridge, forward) (full-bridge, reverse) delay (1) delay (1) relationships: ? period = 4 * t osc * (pr2 + 1) * (tmr2 prescale value) ? pulse width = t osc * (ccpr1l<7:0>:ccp1con<5:4>) * (tmr2 prescale value) ? delay = 4 * t osc * (pwm1con<6:0>) note 1: dead-band delay is programmed using the pwm1con register ( section 11.6.6 ?programmable dead-band delay mode? ).
pic16f882/883/884/886/887 ds41291d-page 134 preliminary ? 2007 microchip technology inc. figure 11-7: example enhanced pwm output relationships (active-low state) 0 period 00 10 01 11 signal pr2+1 p1m<1:0> p1a modulated p1a modulated p1b modulated p1a active p1b inactive p1c inactive p1d modulated p1a inactive p1b modulated p1c active p1d inactive pulse width (single output) (half-bridge) (full-bridge, forward) (full-bridge, reverse) delay (1) delay (1) relationships: ? period = 4 * t osc * (pr2 + 1) * (tmr2 prescale value) ? pulse width = t osc * (ccpr1l<7:0>:ccp1con<5:4>) * (tmr2 prescale value) ? delay = 4 * t osc * (pwm1con<6:0>) note 1: dead-band delay is programmed using the pwm1con register ( section 11.6.6 ?programmable dead-band delay mode? ).
? 2007 microchip technology inc. preliminary ds41291d-page 135 pic16f882/883/884/886/887 11.6.1 half-bridge mode in half-bridge mode, two pins are used as outputs to drive push-pull loads. the pwm output signal is output on the ccpx/p1a pin, while the complementary pwm output signal is output on the p1b pin (see figure 11-9). this mode can be used for half-bridge applications, as shown in figure 11-9, or for full-bridge applications, where four power switches are being modulated with two pwm signals. in half-bridge mode, the programmable dead-band delay can be used to prevent shoot-through current in half-bridge power devices. the value of the pdc<6:0> bits of the pwm1con register sets the number of instruction cycles before the output is driven active. if the value is greater than the duty cycle, the corresponding output remains inactive during the entire cycle. see section 11.6.6 ?programmable dead-band delay mode? for more details of the dead-band delay operations. since the p1a and p1b outputs are multiplexed with the port data latches, the associated tris bits must be cleared to configure p1a and p1b as outputs. figure 11-8: example of half-bridge pwm output figure 11-9: example of half-bridge applications period pulse width td td (1) p1a (2) p1b (2) td = dead-band delay period (1) (1) note 1: at this time, the tmr2 register is equal to the pr2 register. 2: output signals are shown as active-high. p1a p1b fet driver fet driver load + - + - fet driver fet driver v+ load fet driver fet driver p1a p1b standard half-bridge circuit (?push-pull?) half-bridge output driving a full-bridge circuit
pic16f882/883/884/886/887 ds41291d-page 136 preliminary ? 2007 microchip technology inc. 11.6.2 full-bridge mode in full-bridge mode, all four pins are used as outputs. an example of full-bridge application is shown in figure 11-10. in the forward mode, pin ccp1/p1a is driven to its active state, pin p1d is modulated, while p1b and p1c will be driven to their inactive state as shown in figure 11-11. in the reverse mode, p1c is driven to its active state, pin p1b is modulated, while p1a and p1d will be driven to their inactive state as shown figure 11-11. p1a, p1b, p1c and p1d outputs are multiplexed with the port data latches. the associated tris bits must be cleared to configure the p1a, p1b, p1c and p1d pins as outputs. figure 11-10: example of full-bridge application p1a p1c fet driver fet driver v+ v- load fet driver fet driver p1b p1d qa qb qd qc
? 2007 microchip technology inc. preliminary ds41291d-page 137 pic16f882/883/884/886/887 figure 11-11: example of full-bridge pwm output period pulse width p1a (2) p1b (2) p1c (2) p1d (2) forward mode (1) period pulse width p1a (2) p1c (2) p1d (2) p1b (2) reverse mode (1) (1) (1) note 1: at this time, the tmr2 register is equal to the pr2 register. 2: output signal is shown as active-high.
pic16f882/883/884/886/887 ds41291d-page 138 preliminary ? 2007 microchip technology inc. 11.6.2.1 direction change in full-bridge mode in the full-bridge mode, the p1m1 bit in the ccp1con register allows users to control the forward/reverse direction. when the application firmware changes this direction control bit, the module will change to the new direction on the next pwm cycle. a direction change is initiated in software by changing the p1m1 bit of the ccp1con register. the following sequence occurs four timer2 cycles prior to the end of the current pwm period: ? the modulated outputs (p1b and p1d) are placed in their inactive state. ? the associated unmodulated outputs (p1a and p1c) are switched to drive in the opposite direction. ? pwm modulation resumes at the beginning of the next period. see figure 11-12 for an illustration of this sequence. the full-bridge mode does not provide dead-band delay. as one output is modulated at a time, dead-band delay is generally not required. there is a situation where dead-band delay is required. this situation occurs when both of the following conditions are true: 1. the direction of the pwm output changes when the duty cycle of the output is at or near 100%. 2. the turn off time of the power switch, including the power device and driver circuit, is greater than the turn on time. figure 11-13 shows an example of the pwm direction changing from forward to reverse, at a near 100% duty cycle. in this example, at time t1, the output p1a and p1d become inactive, while output p1c becomes active. since the turn off time of the power devices is longer than the turn on time, a shoot-through current will flow through power devices qc and qd (see figure 11-10) for the duration of ?t?. the same phenomenon will occur to power devices qa and qb for pwm direction change from reverse to forward. if changing pwm direction at high duty cycle is required for an application, two possible solutions for eliminating the shoot-through current are: 1. reduce pwm duty cycle for one pwm period before changing directions. 2. use switch drivers that can drive the switches off faster than they can drive them on. other options to prevent shoot-through current may exist. figure 11-12: example of pwm direction change pulse width period (1) signal note 1: the direction bit p1m1 of the ccp1con register is written any time during the pwm cycle. 2: when changing directions, the p1a and p1c signals switch before the end of the current pwm cycle. the modulated p1b and p1d signals are inactive at this time. the length of this time is four timer2 counts. period (2) p1a (active-high) p1b (active-high) p1c (active-high) p1d (active-high) pulse width
? 2007 microchip technology inc. preliminary ds41291d-page 139 pic16f882/883/884/886/887 figure 11-13: example of pwm direction change at near 100% duty cycle forward period reverse period p1a t on t off t = t off ? t on p1b p1c p1d external switch d potential shoot-through current note 1: all signals are shown as active-high. 2: t on is the turn on delay of power switch qc and its driver. 3: t off is the turn off delay of pow er switch qd and its driver. external switch c t1 pw pw
pic16f882/883/884/886/887 ds41291d-page 140 preliminary ? 2007 microchip technology inc. 11.6.3 start-up considerations when any pwm mode is used, the application hardware must use the proper external pull-up and/or pull-down resistors on the pwm output pins. the ccp1m<1:0> bits of the ccp1con register allow the user to choose whether the pwm output signals are active-high or active-low for each pair of pwm output pins (p1a/p1c and p1b/p1d). the pwm output polarities must be selected before the pwm pin output drivers are enabled. changing the polarity configuration while the pwm pin output drivers are enable is not recommended since it may result in damage to the application circuits. the p1a, p1b, p1c and p1d output latches may not be in the proper states when the pwm module is initialized. enabling the pwm pin output drivers at the same time as the enhanced pwm modes may cause damage to the application circuit. the enhanced pwm modes must be enabled in the proper output mode and complete a full pwm cycle before enabling the pwm pin output drivers. the completion of a full pwm cycle is indicated by the tmr2if bit of the pir1 register being set as the second pwm period begins. note: when the microcontroller is released from reset, all of the i/o pins are in the high-impedance state. the external cir- cuits must keep the power switch devices in the off state until the microcontroller drives the i/o pins with the proper signal levels or activates the pwm output(s).
? 2007 microchip technology inc. preliminary ds41291d-page 141 pic16f882/883/884/886/887 11.6.4 enhanced pwm auto-shutdown mode the pwm mode supports an auto-shutdown mode that will disable the pwm outputs when an external shutdown event occurs. auto-shutdown mode places the pwm output pins into a predetermined state. this mode is used to help prevent the pwm from damaging the application. the auto-shutdown sources are selected using the eccpas<2:0> bits of the eccpas register. a shutdown event may be generated by: ?a logic ? 0 ? on the int pin ? comparator c1 ? comparator c2 ? setting the eccpase bit in firmware a shutdown condition is indicated by the eccpase (auto-shutdown event status) bit of the eccpas register. if the bit is a ? 0 ?, the pwm pins are operating normally. if the bit is a ? 1 ?, the pwm outputs are in the shutdown state. when a shutdown event occurs, two things happen: the eccpase bit is set to ? 1 ?. the eccpase will remain set until cleared in firmware or an auto-restart occurs (see section 11.6.5 ?auto-restart mode? ). the enabled pwm pins are asynchronously placed in their shutdown states. the pwm output pins are grouped into pairs [p1a/p1c ] and [p1b/p1d]. the state of each pin pair is determined by the pssac and pssbd bits of the eccpas register. each pin pair may be placed into one of three states: ? drive logic ? 1 ? ? drive logic ? 0 ? ? tri-state (high-impedance) register 11-3: eccpas: enhanced capture/compare/pwm auto-shutdown control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 eccpase eccpas2 eccpas1 eccpas0 pssac1 pssac0 pssbd1 pssbd0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 eccpase: eccp auto-shutdown event status bit 1 = a shutdown event has occurred; eccp outputs are in shutdown state 0 = eccp outputs are operating bit 6-4 eccpas<2:0>: eccp auto-shutdown source select bits 000 = auto-shutdown is disabled 001 = comparator c1 output change 010 = comparator c2 output change (1) 011 = either comparator c1 or c2 change 100 =v il on int pin 101 =v il on int pin or comparator c1 change 110 =v il on int pin or comparator c2 change 111 =v il on int pin or comparator c1 or comparator c2 change bit 3-2 pssacn: pins p1a and p1c shutdown state control bits 00 = drive pins p1a and p1c to ? 0 ? 01 = drive pins p1a and p1c to ? 1 ? 1x = pins p1a and p1c tri-state bit 1-0 pssbdn: pins p1b and p1d shutdown state control bits 00 = drive pins p1b and p1d to ? 0 ? 01 = drive pins p1b and p1d to ? 1 ? 1x = pins p1b and p1d tri-state note 1: if c2sync is enabled, the shutdown will be delayed by timer1.
pic16f882/883/884/886/887 ds41291d-page 142 preliminary ? 2007 microchip technology inc. figure 11-14: pwm auto-shutdown with firmware restart (prsen = 0 ) 11.6.5 auto-restart mode the enhanced pwm can be configured to automati- cally restart the pwm signal once the auto-shutdown condition has been removed. auto-restart is enabled by setting the prsen bit in the pwm1con register. if auto-restart is enabled, the eccpase bit will remain set as long as the auto-shutdown condition is active. when the auto-shutdown condition is removed, the eccpase bit will be cleared via hardware and normal operation will resume. figure 11-15: pwm auto-shutdown with auto-restart enabled (prsen = 1 ) note 1: the auto-shutdown condition is a level-based signal, not an edge-based signal. as long as the level is present, the auto-shutdown will persist. 2: writing to the eccpase bit is disabled while an auto-shutdown condition persists. 3: once the auto-shutdown condition has been removed and the pwm restarted (either through firmware or auto-restart) the pwm signal will always restart at the beginning of the next pwm period. shutdown pwm eccpase bit activity event shutdown event occurs shutdown event clears pwm resumes normal pwm start of pwm period eccpase cleared by firmware pwm period shutdown pwm eccpase bit activity event shutdown event occurs shutdown event clears pwm resumes normal pwm start of pwm period pwm period
? 2007 microchip technology inc. preliminary ds41291d-page 143 pic16f882/883/884/886/887 11.6.6 programmable dead-band delay mode in half-bridge applications where all power switches are modulated at the pwm frequency, the power switches normally require more time to turn off than to turn on. if both the upper and lower power switches are switched at the same time (one turned on, and the other turned off), both switches may be on for a short period of time until one switch completely turns off. during this brief interval, a very high current ( shoot-through current ) will flow through both power switches, shorting the bridge supply. to avoid this potentially destructive shoot-through current from flowing during switching, turning on either of the power switches is normally delayed to allow the other switch to completely turn off. in half-bridge mode, a digitally programmable dead-band delay is available to avoid shoot-through current from destroying the bridge power switches. the delay occurs at the signal transition from the non-active state to the active state. see figure 11-16 for illustration. the lower seven bits of the associated pwm1con register (register 11-4) sets the delay period in terms of microcontroller instruction cycles (t cy or 4 t osc ). figure 11-16: example of half-bridge pwm output figure 11-17: example of half-bridge applications period pulse width td td (1) p1a (2) p1b (2) td = dead-band delay period (1) (1) note 1: at this time, the tmr2 register is equal to the pr2 register. 2: output signals are shown as active-high. p1a p1b fet driver fet driver v+ v- load + v - + v - standard half-bridge circuit (?push-pull?)
pic16f882/883/884/886/887 ds41291d-page 144 preliminary ? 2007 microchip technology inc. register 11-4: pwm1con: enhanced pwm control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 prsen pdc6 pdc5 pdc4 pdc3 pdc2 pdc1 pdc0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 prsen: pwm restart enable bit 1 = upon auto-shutdown, the eccpase bit clears automatically once the shutdown event goes away; the pwm restarts automatically 0 = upon auto-shutdown, eccpase must be cleared in software to restart the pwm bit 6-0 pdc<6:0>: pwm delay count bits pdcn = number of f osc /4 (4 * t osc ) cycles between the scheduled time when a pwm signal should transition active and the actual time it transitions active note 1: bit resets to ? 0 ? with two-speed start-up and lp, xt or hs selected as the oscillator mode or fail-safe mode is enabled.
? 2007 microchip technology inc. preliminary ds41291d-page 145 pic16f882/883/884/886/887 11.6.7 pulse steering mode in single output mode, pulse steering allows any of the pwm pins to be the modulated signal. additionally, the same pwm signal can be simultaneously available on multiple pins. once the single output mode is selected (ccp1m<3:2> = 11 and p1m<1:0> = 00 of the ccp1con register), the user firmware can bring out the same pwm signal to one, two, three or four output pins by setting the appropriate str bits of the pstrcon register, as shown in table 11-5. while the pwm steering mode is active, ccp1m<1:0> bits of the ccp1con register select the pwm output polarity for the p1 pins. the pwm auto-shutdown operation also applies to pwm steering mode as described in section 11.6.4 ?enhanced pwm auto-shutdown mode? . an auto-shutdown event will only affect pins that have pwm outputs enabled. note: the associated tris bits must be set to output (? 0 ?) to enable the pin output driver in order to see the pwm signal on the pin. register 11-5: pstrcon: pulse steering control register (1) u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-1 ? ? ? strsync strd strc strb stra bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4 strsync: steering sync bit 1 = output steering update occurs on next pwm period 0 = output steering update occurs at the beginning of the instruction cycle boundary bit 3 strd: steering enable bit d 1 = p1d pin has the pwm waveform with polarity control from ccpxm<1:0> 0 = p1d pin is assigned to port pin bit 2 strc: steering enable bit c 1 = p1c pin has the pwm waveform with polarity control from ccpxm<1:0> 0 = p1c pin is assigned to port pin bit 1 strb: steering enable bit b 1 = p1b pin has the pwm waveform with polarity control from ccpxm<1:0> 0 = p1b pin is assigned to port pin bit 0 stra: steering enable bit a 1 = p1a pin has the pwm waveform with polarity control from ccpxm<1:0> 0 = p1a pin is assigned to port pin note 1: the pwm steering mode is available only when the ccp1con register bits ccp1m<3:2> = 11 and p1m<1:0> = 00 .
pic16f882/883/884/886/887 ds41291d-page 146 preliminary ? 2007 microchip technology inc. figure 11-18: simplified steering block diagram 1 0 tris p1a pin port data p1a signal stra 1 0 tris p1b pin port data strb 1 0 tris p1c pin port data strc 1 0 tris p1d pin port data strd note 1: port outputs are configured as shown when the ccp1con register bits p1m<1:0> = 00 and ccp1m<3:2> = 11. 2: single pwm output requires setting at least one of the strx bits. ccp1m1 ccp1m0 ccp1m1 ccp1m0
? 2007 microchip technology inc. preliminary ds41291d-page 147 pic16f882/883/884/886/887 11.6.7.1 steering synchronization the strsync bit of the pstrcon register gives the user two selections of when the steering event will happen. when the strsync bit is ? 0 ?, the steering event will happen at the end of the instruction that writes to the pstrcon register. in this case, the output signal at the p1 pins may be an incomplete pwm waveform. this operation is useful when the user firmware needs to immediately remove a pwm signal from the pin. when the strsync bit is ? 1 ?, the effective steering update will happen at the beginning of the next pwm period. in this case, steering on/off the pwm output will always produce a complete pwm waveform. figures 11-19 and 11-20 illustrate the timing diagrams of the pwm steering depending on the strsync setting. figure 11-19: example of steering event at end of instruction (strsync = 0) figure 11-20: example of steering event at beginning of instruction (strsync = 1) pwm p1n = pwm strn p1 port data pwm period port data pwm port data p1n = pwm strn p1 port data
pic16f882/883/884/886/887 ds41291d-page 148 preliminary ? 2007 microchip technology inc. table 11-6: registers associated with capture, compare and timer1 table 11-7: registers associated with pwm and timer2 name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets ccp1con p1m1 p1m0 dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 0000 0000 0000 0000 ccp2con ? ? dc2b1 dc2b0 ccp2m3 ccp2m2 ccp2m1 ccp2m0 --00 0000 --00 0000 ccpr1l capture/compare/pwm register 1 low byte (lsb) xxxx xxxx xxxx xxxx ccpr1h capture/compare/pwm register 1 high byte (msb) xxxx xxxx xxxx xxxx ccpr2l capture/compare/pwm register 2 low byte (lsb) xxxx xxxx xxxx xxxx ccpr2h capture/compare/pwm register 2 high byte (msb) xxxx xxxx xxxx xxxx cm2con1 mc1out mc2out c1rsel c2rsel ? ?t1gss c2sync 0000 --10 0000 --10 intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x pie1 ? adie rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 pie2 osfie c2ie c1ie eeie bclie ulpwuie ? ccp2ie 0000 00-0 0000 00-0 pir1 ? adif rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 pir2 osfif c2if c1if eeif bclif ulpwuif ? ccp2if 0000 00-0 0000 00-0 t1con t1ginv tmr1ge t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on 0000 0000 0000 0000 tmr1l holding register for the least significant byte of the 16-bit tmr1 register xxxx xxxx xxxx xxxx tmr1h holding register for the most significant byte of the 16-bit tmr1 register xxxx xxxx xxxx xxxx trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 1111 1111 1111 1111 legend: ? = unimplemented locations, read as ? 0 ?, u = unchanged, x = unknown. shaded cells are not used by the capture and compare. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets ccp1con p1m1 p1m0 dc1b1 dc1b0 ccp1m3 ccp1m2 ccp1m1 ccp1m0 0000 0000 0000 0000 ccp2con ? ? dc2b1 dc2b0 ccp2m3 ccp2m2 ccp2m1 ccp2m0 --00 0000 --00 0000 eccpas eccpase eccpas2 eccpas1 eccpas0 pssac1 pssac0 pssbd1 pssbd0 0000 0000 0000 0000 intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x pr2 timer2 period register 1111 1111 1111 1111 pstrcon ? ? ? strsync strd strc strb stra ---0 0001 ---0 0001 pwm1con prsen pdc6 pdc5 pdc4 pdc3 pdc2 pdc1 pdc0 0000 0000 0000 0000 t2con ? toutps3 toutps2 toutps1 toutps0 tmr2on t2ckps1 t2ckps0 -000 0000 -000 0000 tmr2 timer2 module register 0000 0000 0000 0000 trisb trisb7 trisb6 trisb5 trisb4 trisb3 trisb2 trisb1 trisb0 1111 1111 1111 1111 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 1111 1111 1111 1111 trisd trisd7 trisd6 trisd5 trisd4 trisd3 trisd2 trisd1 trisd0 1111 1111 1111 1111 legend: ? = unimplemented locations, read as ? 0 ?, u = unchanged, x = unknown. shaded cells ar e not used by the pwm.
? 2007 microchip technology inc. preliminary ds41291d-page 149 pic16f822/883/884/886/887 12.0 enhanced universal synchronous asynchronous receiver transmitter (eusart) the enhanced universal synchronous asynchronous receiver transmitter (eusart) module is a serial i/o communications peripheral. it contains all the clock generators, shift registers and data buffers necessary to perform an input or output serial data transfer independent of device program execution. the eusart, also known as a serial communications interface (sci), can be configured as a full-duplex asynchronous system or half-duplex synchronous system. full-duplex mode is useful for communications with peripheral systems, such as crt terminals and personal computers. half-duplex synchronous mode is intended for communications with peripheral devices, such as a/d or d/a integrated circuits, serial eeproms or other microcontrollers. these devices typically do not have internal clocks for baud rate generation and require the external clock signal provided by a master synchronous device. the eusart module includes the following capabilities: ? full-duplex asynchronous transmit and receive ? two-character input buffer ? one-character output buffer ? programmable 8-bit or 9-bit character length ? address detection in 9-bit mode ? input buffer overrun error detection ? received character framing error detection ? half-duplex synchronous master ? half-duplex synchronous slave ? programmable clock polarity in synchronous modes the eusart module implements the following additional features, making it ideally suited for use in local interconnect network (lin) bus systems: ? automatic detection and calibration of the baud rate ? wake-up on break reception ? 13-bit break character transmit block diagrams of the eusart transmitter and receiver are shown in figure 12-1 and figure 12-2. figure 12-1: eusart transmi t block diagram txif txie interrupt txen tx9d msb lsb data bus txreg register transmit shift register (tsr) (8) 0 tx9 trmt spen tx/ck pin pin buffer and control 8 spbrg spbrgh brg16 f osc n n + 1 multiplier x4 x16 x64 sync 1x00 0 brgh x110 0 brg16 x101 0 baud rate generator ???
pic16f822/883/884/886/887 ds41291d-page 150 preliminary ? 2007 microchip technology inc. figure 12-2: eusart receiv e block diagram the operation of the eusart module is controlled through three registers: ? transmit status and control (txsta) ? receive status and control (rcsta) ? baud rate control (baudctl) these registers are detailed in register 12-1, register 12-2 and register 12-3, respectively. rx/dt pin pin buffer and control spen data recovery cren oerr ferr rsr register msb lsb rx9d rcreg register fifo interrupt rcif rcie data bus 8 stop start (8) 7 1 0 rx9 ? ? ? spbrg spbrgh brg16 rcidl f osc n n + 1 multiplier x4 x16 x64 sync 1x00 0 brgh x110 0 brg16 x101 0 baud rate generator
? 2007 microchip technology inc. preliminary ds41291d-page 151 pic16f822/883/884/886/887 12.1 eusart asynchronous mode the eusart transmits and receives data using the standard non-return-to-zero (nrz) format. nrz is implemented with two levels: a v oh mark state which represents a ? 1 ? data bit, and a v ol space state which represents a ? 0 ? data bit. nrz refers to the fact that consecutively transmitted data bits of the same value stay at the output level of that bit without returning to a neutral level between each bit transmission. an nrz transmission port idles in the mark state. each character transmission consists of one start bit followed by eight or nine data bits and is always terminated by one or more stop bits. the start bit is always a space and the stop bits are always marks. the most common data format is 8 bits. each transmitted bit persists for a period of 1/(baud rate). an on-chip dedicated 8-bit/16-bit baud rate generator is used to derive standard baud rate frequencies from the system oscillator. see table 12-5 for examples of baud rate configurations. the eusart transmits and receives the lsb first. the eusart?s transmitter and receiver are functionally independent, but share the same data format and baud rate. parity is not supported by the hardware, but can be implemented in software and stored as the ninth data bit. 12.1.1 eusart asynchronous transmitter the eusart transmitter block diagram is shown in figure 12-1. the heart of the transmitter is the serial transmit shift register (tsr), which is not directly accessible by software. the tsr obtains its data from the transmit buffer, which is the txreg register. 12.1.1.1 enabling the transmitter the eusart transmitter is enabled for asynchronous operations by configuring the following three control bits: ?txen = 1 ? sync = 0 ? spen = 1 all other eusart control bits are assumed to be in their default state. setting the txen bit of the txsta register enables the transmitter circuitry of the eusart. clearing the sync bit of the txsta register configures the eusart for asynchronous operation. setting the spen bit of the rcsta register enables the eusart and automatically configures the tx/ck i/o pin as an output. if the tx/ck pin is shared with an analog peripheral the analog i/o function must be disabled by clearing the corresponding ansel bit. 12.1.1.2 transmitting data a transmission is initiated by writing a character to the txreg register. if this is the first character, or the previous character has been completely flushed from the tsr, the data in the txreg is immediately transferred to the tsr register. if the tsr still contains all or part of a previous character, the new character data is held in the txreg until the stop bit of the previous character has been transmitted. the pending character in the txreg is then transferred to the tsr in one t cy immediately following the stop bit transmission. the transmission of the start bit, data bits and stop bit sequence commences immediately following the transfer of the data to the tsr from the txreg. 12.1.1.3 transmit interrupt flag the txif interrupt flag bit of the pir1 register is set whenever the eusart transmitter is enabled and no character is being held for transmission in the txreg. in other words, the txif bit is only clear when the tsr is busy with a character and a new character has been queued for transmission in the txreg. the txif flag bit is not cleared immediately upon writing txreg. txif becomes valid in the second instruction cycle following the write execution. polling txif immediately following the txreg write will return invalid results. the txif bit is read-only, it cannot be set or cleared by software. the txif interrupt can be enabled by setting the txie interrupt enable bit of the pie1 register. however, the txif flag bit will be set whenever the txreg is empty, regardless of the state of txie enable bit. to use interrupts when transmitting data, set the txie bit only when there is more data to send. clear the txie interrupt enable bit upon writing the last character of the transmission to the txreg. note 1: when the spen bit is set the rx/dt i/o pin is automatically configured as an input, regardless of the state of the corresponding tris bit and whether or not the eusart receiver is enabled. the rx/dt pin data can be read via a normal port read but port latch data output is precluded. 2: the txif transmitter interrupt flag is set when the txen enable bit is set.
pic16f822/883/884/886/887 ds41291d-page 152 preliminary ? 2007 microchip technology inc. 12.1.1.4 tsr status the trmt bit of the txsta register indicates the status of the tsr register. this is a read-only bit. the trmt bit is set when the tsr register is empty and is cleared when a character is transferred to the tsr register from the txreg. the trmt bit remains clear until all bits have been shifted out of the tsr register. no interrupt logic is tied to this bit, so the user has to poll this bit to determine the tsr status. 12.1.1.5 transmitting 9-bit characters the eusart supports 9-bit character transmissions. when the tx9 bit of the txsta register is set the eusart will shift 9 bits out for each character transmit- ted. the tx9d bit of the txsta register is the ninth, and most significant, data bit. when transmitting 9-bit data, the tx9d data bit must be written before writing the 8 least significant bits into the txreg. all nine bits of data will be transferred to the tsr shift register immediately after the txreg is written. a special 9-bit address mode is available for use with multiple receivers. see section 12.1.2.7 ?address detection? for more information on the address mode. 12.1.1.6 asynchronous transmission set-up: 1. initialize the spbrgh, spbrg register pair and the brgh and brg16 bits to achieve the desired baud rate (see section 12.3 ?eusart baud rate generator (brg)? ). 2. enable the asynchronous serial port by clearing the sync bit and setting the spen bit. 3. if 9-bit transmission is desired, set the tx9 con- trol bit. a set ninth data bit will indicate that the 8 least significant data bits are an address when the receiver is set for address detection. 4. enable the transmission by setting the txen control bit. this will cause the txif interrupt bit to be set. 5. if interrupts are desired, set the txie interrupt enable bit. an interrupt will occur immediately provided that the gie and peie bits of the intcon register are also set. 6. if 9-bit transmission is selected, the ninth bit should be loaded into the tx9d data bit. 7. load 8-bit data into the txreg register. this will start the transmission. figure 12-3: asynchronous transmission figure 12-4: asynchronous transmiss ion (back-to-back) note: the tsr register is not mapped in data memory, so it is not available to the user. word 1 stop bit word 1 transmit shift reg start bit bit 0 bit 1 bit 7/8 write to txreg word 1 brg output (shift clock) rc4/c2out/tx/ck txif bit (transmit buffer reg. empty flag) trmt bit (transmit shift reg. empty flag) 1 t cy pin transmit shift reg. write to txreg brg output (shift clock) rc4/c2out/tx/ck txif bit (interrupt reg. flag) trmt bit (transmit shift reg. empty flag) word 1 word 2 word 1 word 2 start bit stop bit start bit transmit shift reg. word 1 word 2 bit 0 bit 1 bit 7/8 bit 0 note: this timing diagram shows two consecutive transmissions. 1 t cy 1 t cy pin
? 2007 microchip technology inc. preliminary ds41291d-page 153 pic16f822/883/884/886/887 table 12-1: registers associated with asynchronous transmission namebit 7bit 6bit 5bit 4bit 3bit 2bit 1bit 0 value on por, bor value on all other resets baudctl abdovf rcidl ? sckp brg16 ? wue abden 01-0 0-00 01-0 0-00 intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x pie1 ? adie rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 pir1 ? adif rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 rcreg eusart receive data register 0000 0000 0000 0000 rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x spbrg brg7 brg6 brg5 brg4 brg3 brg2 brg1 brg0 0000 0000 0000 0000 spbrgh brg15 brg14 brg13 brg12 brg11 brg10 brg9 brg8 0000 0000 0000 0000 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 1111 1111 1111 1111 txreg eusart transmit data register 0000 0000 0000 0000 txsta csrc tx9 txen sync sendb brgh trmt tx9d 0000 0010 0000 0010 legend: x = unknown, ? = unimplemented read as ? 0 ?. shaded cells are not used for asynchronous transmission.
pic16f822/883/884/886/887 ds41291d-page 154 preliminary ? 2007 microchip technology inc. 12.1.2 eusart asynchronous receiver the asynchronous mode would typically be used in rs-232 systems. the receiver block diagram is shown in figure 12-2. the data is received on the rx/dt pin and drives the data recovery block. the data recovery block is actually a high-speed shifter operating at 16 times the baud rate, whereas the serial receive shift register (rsr) operates at the bit rate. when all 8 or 9 bits of the character have been shifted in, they are immediately transferred to a two character first-in- first-out (fifo) memory. the fifo buffering allows reception of two complete characters and the start of a third character before software must start servicing the eusart receiver. the fifo and rsr registers are not directly accessible by software. access to the received data is via the rcreg register. 12.1.2.1 enabling the receiver the eusart receiver is enabled for asynchronous operation by configuring the following three control bits: ? cren = 1 ? sync = 0 ? spen = 1 all other eusart control bits are assumed to be in their default state. setting the cren bit of the rcsta register enables the receiver circuitry of the eusart. clearing the sync bit of the txsta register configures the eusart for asynchronous operation. setting the spen bit of the rcsta register enables the eusart and automatically configures the rx/dt i/o pin as an input. if the rx/dt pin is shared with an analog peripheral the analog i/o function must be disabled by clearing the corresponding ansel bit. 12.1.2.2 receiving data the receiver data recovery circuit initiates character reception on the falling edge of the first bit. the first bit, also known as the start bit, is always a zero. the data recovery circuit counts one-half bit time to the center of the start bit and verifies that the bit is still a zero. if it is not a zero then the data recovery circuit aborts character reception, without generating an error, and resumes looking for the falling edge of the start bit. if the start bit zero verification succeeds then the data recovery circuit counts a full bit time to the center of the next bit. the bit is then sampled by a majority detect circuit and the resulting ? 0 ? or ? 1 ? is shifted into the rsr. this repeats until all data bits have been sampled and shifted into the rsr. one final bit time is measured and the level sampled. this is the stop bit, which is always a ? 1 ?. if the data recovery circuit samples a ? 0 ? in the stop bit position then a framing error is set for this character, otherwise the framing error is cleared for this character. see section 12.1.2.4 ?receive framing error? for more information on framing errors. immediately after all data bits and the stop bit have been received, the character in the rsr is transferred to the eusart receive fifo and the rcif interrupt flag bit of the pir1 register is set. the top character in the fifo is transferred out of the fifo by reading the rcreg register. 12.1.2.3 receive interrupts the rcif interrupt flag bit of the pir1 register is set whenever the eusart receiver is enabled and there is an unread character in the receive fifo. the rcif interrupt flag bit is read-only, it cannot be set or cleared by software. rcif interrupts are enabled by setting the following bits: ? rcie interrupt enable bit of the pie1 register ? peie peripheral interrupt enable bit of the intcon register ? gie global interrupt enable bit of the intcon register the rcif interrupt flag bit will be set when there is an unread character in the fifo, regardless of the state of interrupt enable bits. note: when the spen bit is set the tx/ck i/o pin is automatically configured as an output, regardless of the state of the corresponding tris bit and whether or not the eusart transmitter is enabled. the port latch is disconnected from the output driver so it is not possible to use the tx/ck pin as a general purpose output. note: if the receive fifo is overrun, no additional characters will be received until the overrun condition is cleared. see section 12.1.2.5 ?receive overrun error? for more information on overrun errors.
? 2007 microchip technology inc. preliminary ds41291d-page 155 pic16f822/883/884/886/887 12.1.2.4 receive framing error each character in the receive fifo buffer has a corresponding framing error status bit. a framing error indicates that a stop bit was not seen at the expected time. the framing error status is accessed via the ferr bit of the rcsta register. the ferr bit represents the status of the top unread character in the receive fifo. therefore, the ferr bit must be read before reading the rcreg. the ferr bit is read-only and only applies to the top unread character in the receive fifo. a framing error (ferr = 1 ) does not preclude reception of additional characters. it is not necessary to clear the ferr bit. reading the next character from the fifo buffer will advance the fifo to the next character and the next corresponding framing error. the ferr bit can be forced clear by clearing the spen bit of the rcsta register which resets the eusart. clearing the cren bit of the rcsta register does not affect the ferr bit. a framing error by itself does not generate an interrupt. 12.1.2.5 receive overrun error the receive fifo buffer can hold two characters. an overrun error will be generated if a third character, in its entirety, is received before the fifo is accessed. when this happens the oerr bit of the rcsta register is set. the characters already in the fifo buffer can be read but no additional characters will be received until the error is cleared. the error must be cleared by either clearing the cren bit of the rcsta register or by resetting the eusart by clearing the spen bit of the rcsta register. 12.1.2.6 receiving 9-bit characters the eusart supports 9-bit character reception. when the rx9 bit of the rcsta register is set the eusart will shift 9 bits into the rsr for each character received. the rx9d bit of the rcsta register is the ninth and most significant data bit of the top unread character in the receive fifo. when reading 9-bit data from the receive fifo buffer, the rx9d data bit must be read before reading the 8 least significant bits from the rcreg. 12.1.2.7 address detection a special address detection mode is available for use when multiple receivers share the same transmission line, such as in rs-485 systems. address detection is enabled by setting the adden bit of the rcsta register. address detection requires 9-bit character reception. when address detection is enabled, only characters with the ninth data bit set will be transferred to the receive fifo buffer, thereby setting the rcif interrupt bit. all other characters will be ignored. upon receiving an address character, user software determines if the address matches its own. upon address match, user software must disable address detection by clearing the adden bit before the next stop bit occurs. when user software detects the end of the message, determined by the message protocol used, software places the receiver back into the address detection mode by setting the adden bit. note: if all receive characters in the receive fifo have framing errors, repeated reads of the rcreg will not clear the ferr bit.
pic16f822/883/884/886/887 ds41291d-page 156 preliminary ? 2007 microchip technology inc. 12.1.2.8 asynchronous reception set-up: 1. initialize the spbrgh, spbrg register pair and the brgh and brg16 bits to achieve the desired baud rate (see section 12.3 ?eusart baud rate generator (brg)? ). 2. enable the serial port by setting the spen bit. the sync bit must be clear for asynchronous operation. 3. if interrupts are desired, set the rcie interrupt enable bit and set the gie and peie bits of the intcon register. 4. if 9-bit reception is desired, set the rx9 bit. 5. enable reception by setting the cren bit. 6. the rcif interrupt flag bit will be set when a character is transferred from the rsr to the receive buffer. an interrupt will be generated if the rcie interrupt enable bit was also set. 7. read the rcsta register to get the error flags and, if 9-bit data reception is enabled, the ninth data bit. 8. get the received 8 least significant data bits from the receive buffer by reading the rcreg register. 9. if an overrun occurred, clear the oerr flag by clearing the cren receiver enable bit. 12.1.2.9 9-bit address detection mode set-up this mode would typically be used in rs-485 systems. to set up an asynchronous reception with address detect enable: 1. initialize the spbrgh, spbrg register pair and the brgh and brg16 bits to achieve the desired baud rate (see section 12.3 ?eusart baud rate generator (brg)? ). 2. enable the serial port by setting the spen bit. the sync bit must be clear for asynchronous operation. 3. if interrupts are desired, set the rcie interrupt enable bit and set the gie and peie bits of the intcon register. 4. enable 9-bit reception by setting the rx9 bit. 5. enable address detection by setting the adden bit. 6. enable reception by setting the cren bit. 7. the rcif interrupt flag bit will be set when a character with the ninth bit set is transferred from the rsr to the receive buffer. an interrupt will be generated if the rcie interrupt enable bit was also set. 8. read the rcsta register to get the error flags. the ninth data bit will always be set. 9. get the received 8 least significant data bits from the receive buffer by reading the rcreg register. software determines if this is the device?s address. 10. if an overrun occurred, clear the oerr flag by clearing the cren receiver enable bit. 11. if the device has been addressed, clear the adden bit to allow all received data into the receive buffer and generate interrupts. figure 12-5: asynchronous reception start bit bit 7/8 bit 1 bit 0 bit 7/8 bit 0 stop bit start bit start bit bit 7/8 stop bit rx/dt pin reg rcv buffer reg rcv shift read rcv buffer reg rcreg rcif (interrupt flag) oerr bit cren word 1 rcreg word 2 rcreg stop bit note: this timing diagram shows three words appearing on the rx input. the rcreg (receive buffer) is read after the third word, causing the oerr (overrun) bit to be set. rcidl
? 2007 microchip technology inc. preliminary ds41291d-page 157 pic16f822/883/884/886/887 table 12-2: registers associated with asynchronous reception namebit 7bit 6bit 5bit 4bit 3bit 2bit 1bit 0 value on por, bor value on all other resets baudctl abdovf rcidl ? sckp brg16 ? wue abden 01-0 0-00 01-0 0-00 intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x pie1 ? adie rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 pir1 ? adif rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 rcreg eusart receive data register 0000 0000 0000 0000 rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x spbrg brg7 brg6 brg5 brg4 brg3 brg2 brg1 brg0 0000 0000 0000 0000 spbrgh brg15 brg14 brg13 brg12 brg11 brg10 brg9 brg8 0000 0000 0000 0000 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 1111 1111 1111 1111 txreg eusart transmit data register 0000 0000 0000 0000 txsta csrc tx9 txen sync sendb brgh trmt tx9d 0000 0010 0000 0010 legend: x = unknown, ? = unimplemented read as ? 0 ?. shaded cells are not used for asynchronous reception.
pic16f822/883/884/886/887 ds41291d-page 158 preliminary ? 2007 microchip technology inc. 12.2 clock accuracy with asynchronous operation the factory calibrates the internal oscillator block out- put (intosc). however, the intosc frequency may drift as v dd or temperature changes, and this directly affects the asynchronous baud rate. two methods may be used to adjust the baud rate clock, but both require a reference clock source of some kind. the first (preferred) method uses the osctune register to adjust the intosc output. adjusting the value in the osctune register allows for fine resolution changes to the system clock source. see 4.5 ?internal clock modes? for more information. the other method adjusts the value in the baud rate generator. this can be done automatically with the auto-baud detect feature (see section 12.3.1 ?auto- baud detect? ). there may not be fine enough resolution when adjusting the baud rate generator to compensate for a gradual change in the peripheral clock frequency. register 12-1: txsta: transmit status and control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-1 r/w-0 csrc tx9 txen (1) sync sendb brgh trmt tx9d bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 csrc: clock source select bit asynchronous mode : don?t care synchronous mode : 1 = master mode (clock generated internally from brg) 0 = slave mode (clock from external source) bit 6 tx9: 9-bit transmit enable bit 1 = selects 9-bit transmission 0 = selects 8-bit transmission bit 5 txen: transmit enable bit (1) 1 = transmit enabled 0 = transmit disabled bit 4 sync: eusart mode select bit 1 = synchronous mode 0 = asynchronous mode bit 3 sendb: send break character bit asynchronous mode : 1 = send sync break on next transmission (cleared by hardware upon completion) 0 = sync break transmission completed synchronous mode : don?t care bit 2 brgh: high baud rate select bit asynchronous mode : 1 = high speed 0 = low speed synchronous mode: unused in this mode bit 1 trmt: transmit shift register status bit 1 = tsr empty 0 = tsr full bit 0 tx9d: ninth bit of transmit data can be address/data bit or a parity bit. note 1: sren/cren overrides txen in sync mode.
? 2007 microchip technology inc. preliminary ds41291d-page 159 pic16f822/883/884/886/887 register 12-2: rcsta: receive status and control register (1) r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-0 r-0 r-x spen rx9 sren cren adden ferr oerr rx9d bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 spen: serial port enable bit 1 = serial port enabled (configures rx/dt and tx/ck pins as serial port pins) 0 = serial port disabled (held in reset) bit 6 rx9: 9-bit receive enable bit 1 = selects 9-bit reception 0 = selects 8-bit reception bit 5 sren: single receive enable bit asynchronous mode : don?t care synchronous mode ? master : 1 = enables single receive 0 = disables single receive this bit is cleared after reception is complete. synchronous mode ? slave don?t care bit 4 cren: continuous receive enable bit asynchronous mode : 1 = enables receiver 0 = disables receiver synchronous mode : 1 = enables continuous receive until enable bit cren is cleared (cren overrides sren) 0 = disables continuous receive bit 3 adden: address detect enable bit asynchronous mode 9-bit (rx9 = 1 ) : 1 = enables address detection, enable interrupt and load the receive buffer when rsr<8> is set 0 = disables address detection, all bytes are received and ninth bit can be used as parity bit asynchronous mode 8-bit (rx9 = 0 ) : don?t care bit 2 ferr: framing error bit 1 = framing error (can be updated by reading rcreg register and receive next valid byte) 0 = no framing error bit 1 oerr: overrun error bit 1 = overrun error (can be cleared by clearing bit cren) 0 = no overrun error bit 0 rx9d: ninth bit of received data this can be address/data bit or a parity bit and must be calculated by user firmware.
pic16f822/883/884/886/887 ds41291d-page 160 preliminary ? 2007 microchip technology inc. register 12-3: baudctl: baud rate control register r-0 r-1 u-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 abdovf rcidl ? sckp brg16 ? wue abden bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 abdovf: auto-baud detect overflow bit asynchronous mode : 1 = auto-baud timer overflowed 0 = auto-baud timer did not overflow synchronous mode : don?t care bit 6 rcidl : receive idle flag bit asynchronous mode : 1 = receiver is idle 0 = start bit has been received and the receiver is receiving synchronous mode : don?t care bit 5 unimplemented: read as ? 0 ? bit 4 sckp : synchronous clock polarity select bit asynchronous mode : 1 = transmit inverted data to the rb7/tx/ck pin 0 = transmit non-inverted data to the rb7/tx/ck pin synchronous mode : 1 = data is clocked on rising edge of the clock 0 = data is clocked on falling edge of the clock bit 3 brg16: 16-bit baud rate generator bit 1 = 16-bit baud rate generator is used 0 = 8-bit baud rate generator is used bit 2 unimplemented: read as ? 0 ? bit 1 wue: wake-up enable bit asynchronous mode : 1 = receiver is waiting for a falling edge. no character will be received byte rcif will be set. wue will automatically clear after rcif is set. 0 = receiver is operating normally synchronous mode : don?t care bit 0 abden : auto-baud detect enable bit asynchronous mode : 1 = auto-baud detect mode is enabled (clears when auto-baud is complete) 0 = auto-baud detect mode is disabled synchronous mode : don?t care
? 2007 microchip technology inc. preliminary ds41291d-page 161 pic16f822/883/884/886/887 12.3 eusart baud rate generator (brg) the baud rate generator (brg) is an 8-bit or 16-bit timer that is dedicated to the support of both the asynchronous and synchronous eusart operation. by default, the brg operates in 8-bit mode. setting the brg16 bit of the baudctl register selects 16-bit mode. the spbrgh, spbrg register pair determines the period of the free running baud rate timer. in asynchronous mode the multiplier of the baud rate period is determined by both the brgh bit of the txsta register and the brg16 bit of the baudctl register. in synchronous mode, the brgh bit is ignored. table 12-3 contains the formulas for determining the baud rate. example 12-1 provides a sample calculation for determining the baud rate and baud rate error. typical baud rates and error values for various asynchronous modes have been computed for your convenience and are shown in table 12-3. it may be advantageous to use the high baud rate (brgh = 1 ), or the 16-bit brg (brg16 = 1 ) to reduce the baud rate error. the 16-bit brg mode is used to achieve slow baud rates for fast oscillator frequencies. writing a new value to the spbrgh, spbrg register pair causes the brg timer to be reset (or cleared). this ensures that the brg does not wait for a timer overflow before outputting the new baud rate. if the system clock is changed during an active receive operation, a receive error or data loss may result. to avoid this problem, check the status of the rcidl bit to make sure that the receive operation is idle before changing the system clock. example 12-1: calculating baud rate error table 12-3: baud rate formulas table 12-4: registers associated with the baud rate generator for a device with f osc of 16 mhz, desired baud rat e of 9600, asynchronous mode, 8-bit brg: solving for spbrgh:spbrg: x f osc desired baud rate --------------------------------------------- 64 --------------------------------------------- 1 ? = desired baud rate f osc 64 [spbrgh:spbrg] 1 + () -------------------------------------------------------------------- - = 16000000 9600 ----------------------- - 64 ----------------------- - 1 ? = 25.042 [] 25 == calculated baud rate 16000000 64 25 1 + () -------------------------- - = 9615 = error calc. baud rate desired baud rat e ? desired baud rate ----------------------------------------------------------------------------------------- --- = 9615 9600 ? () 9600 ---------------------------------- 0.16% == configuration bits brg/eusart mode baud rate formula sync brg16 brgh 000 8-bit/asynchronous f osc /[64 (n+1)] 001 8-bit/asynchronous f osc /[16 (n+1)] 010 16-bit/asynchronous 011 16-bit/asynchronous f osc /[4 (n+1)] 10x 8-bit/synchronous 11x 16-bit/synchronous legend: x = don?t care, n = value of spbrgh, spbrg register pair namebit 7bit 6bit 5bit 4bit 3bit 2bit 1bit 0 value on por, bor value on all other resets baudctl abdovf rcidl ? sckp brg16 ? wue abden 01-0 0-00 01-0 0-00 rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x spbrg brg7 brg6 brg5 brg4 brg3 brg2 brg1 brg0 0000 0000 0000 0000 spbrgh brg15 brg14 brg13 brg12 brg11 brg10 brg9 brg8 0000 0000 0000 0000 txsta csrc tx9 txen sync sendb brgh trmt tx9d 0000 0010 0000 0010 legend: x = unknown, ? = unimplemented read as ? 0 ?. shaded cells are not used for the baud rate generator.
pic16f822/883/884/886/887 ds41291d-page 162 preliminary ? 2007 microchip technology inc. table 12-5: baud rates for asynchronous modes baud rate sync = 0 , brgh = 0 , brg16 = 0 f osc = 20.000 mhz f osc = 18.432 mhz f osc = 11.0592 mhz f osc = 8.000 mhz actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) 300?? ? ?? ? ?? ? ?? ? 1200 1221 1.73 255 1200 0.00 239 1200 0.00 143 1202 0.16 103 2400 2404 0.16 129 2400 0.00 119 2400 0.00 71 2404 0.16 51 9600 9470 -1.36 32 9600 0.00 29 9600 0.00 17 9615 0.16 12 10417 10417 0.00 29 10286 -1.26 27 10165 -2.42 16 10417 0.00 11 19.2k 19.53k 1.73 15 19.20k 0.00 14 19.20k 0.00 8 ? ? ? 57.6k ? ? ? 57.60k 0.00 7 57.60k 0.00 2 ? ? ? 115.2k ? ? ? ? ? ? ? ? ? ? ? ? baud rate sync = 0 , brgh = 0 , brg16 = 0 f osc = 4.000 mhz f osc = 3.6864 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) 300 300 0.16 207 300 0.00 191 300 0.16 103 300 0.16 51 1200 1202 0.16 51 1200 0.00 47 1202 0.16 25 1202 0.16 12 2400 2404 0.16 25 2400 0.00 23 2404 0.16 12 ? ? ? 9600 ? ? ? 9600 0.00 5 ? ? ? ? ? ? 10417 10417 0.00 5 ? ? ? 10417 0.00 2 ? ? ? 19.2k ? ? ? 19.20k 0.00 2 ? ? ? ? ? ? 57.6k ? ? ? 57.60k 0.00 0 ? ? ? ? ? ? 115.2k ? ? ? ? ? ? ? ? ? ? ? ? baud rate sync = 0 , brgh = 1 , brg16 = 0 f osc = 20.000 mhz f osc = 18.432 mhz f osc = 11.0592 mhz f osc = 8.000 mhz actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) 300 ?? ? ?? ? ?? ? ?? ? 1200 ? ? ? ? ? ? ? ? ? ? ? ? 2400 ? ? ? ? ? ? ?? ? 2404 0.16 207 9600 9615 0.16 129 9600 0.00 119 9600 0.00 71 9615 0.16 51 10417 10417 0.00 119 10378 -0.37 110 10473 0.53 65 10417 0.00 47 19.2k 19.23k 0.16 64 19.20k 0.00 59 19.20k 0.00 35 19231 0.16 25 57.6k 56.82k -1.36 21 57.60k 0.00 19 57.60k 0.00 11 55556 -3.55 8 115.2k 113.64k -1.36 10 115.2k 0.00 9 115.2k 0.00 5 ? ? ?
? 2007 microchip technology inc. preliminary ds41291d-page 163 pic16f822/883/884/886/887 baud rate sync = 0 , brgh = 1 , brg16 = 0 f osc = 4.000 mhz f osc = 3.6864 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) 300 ? ? ? ? ? ? ? ? ? 300 0.16 207 1200 1202 0.16 207 1200 0.00 191 1202 0.16 103 1202 0.16 51 2400 2404 0.16 103 2400 0.00 95 2404 0.16 51 2404 0.16 25 9600 9615 0.16 25 9600 0.00 23 9615 0.16 12 ? ? ? 10417 10417 0.00 23 10473 0.53 21 10417 0.00 11 10417 0.00 5 19.2k 19.23k 0.16 12 19.2k 0.00 11 ? ? ? ? ? ? 57.6k ? ? ? 57.60k 0.00 3 ? ? ? ? ? ? 115.2k ? ? ? 115.2k 0.00 1 ? ? ? ? ? ? baud rate sync = 0 , brgh = 0 , brg16 = 1 f osc = 20.000 mhz f osc = 18.432 mhz f osc = 11.0592 mhz f osc = 8.000 mhz actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) 300 300.0 -0.01 4166 300.0 0.00 3839 300.0 0.00 2303 299.9 -0.02 1666 1200 1200 -0.03 1041 1200 0.00 959 1200 0.00 575 1199 -0.08 416 2400 2399 -0.03 520 2400 0.00 479 2400 0.00 287 2404 0.16 207 9600 9615 0.16 129 9600 0.00 119 9600 0.00 71 9615 0.16 51 10417 10417 0.00 119 10378 -0.37 110 10473 0.53 65 10417 0.00 47 19.2k 19.23k 0.16 64 19.20k 0.00 59 19.20k 0.00 35 19.23k 0.16 25 57.6k 56.818 -1.36 21 57.60k 0.00 19 57.60k 0.00 11 55556 -3.55 8 115.2k 113.636 -1.36 10 115.2k 0.00 9 115.2k 0.00 5 ? ? ? baud rate sync = 0 , brgh = 0 , brg16 = 1 f osc = 4.000 mhz f osc = 3.6864 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) 300 300.1 0.04 832 300.0 0.00 767 299.8 -0.108 416 300.5 0.16 207 1200 1202 0.16 207 1200 0.00 191 1202 0.16 103 1202 0.16 51 2400 2404 0.16 103 2400 0.00 95 2404 0.16 51 2404 0.16 25 9600 9615 0.16 25 9600 0.00 23 9615 0.16 12 ? ? ? 10417 10417 0.00 23 10473 0.53 21 10417 0.00 11 10417 0.00 5 19.2k 19.23k 0.16 12 19.20k 0.00 11 ? ? ? ? ? ? 57.6k ? ? ? 57.60k 0.00 3 ? ? ? ? ? ? 115.2k ? ? ? 115.2k 0.00 1 ? ? ? ? ? ? table 12-5: baud rates for asynchronous modes (continued)
pic16f822/883/884/886/887 ds41291d-page 164 preliminary ? 2007 microchip technology inc. baud rate sync = 0 , brgh = 1 , brg16 = 1 or sync = 1 , brg16 = 1 f osc = 20.000 mhz f osc = 18.432 mhz f osc = 11.0592 mhz f osc = 8.000 mhz actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) 300 300.0 0.00 16665 300.0 0.00 15359 300.0 0.00 9215 300.0 0.00 6666 1200 1200 -0.01 4166 1200 0.00 3839 1200 0.00 2303 1200 -0.02 1666 2400 2400 0.02 2082 2400 0.00 1919 2400 0.00 1151 2401 0.04 832 9600 9597 -0.03 520 9600 0.00 479 9600 0.00 287 9615 0.16 207 10417 10417 0.00 479 10425 0.08 441 10433 0.16 264 10417 0 191 19.2k 19.23k 0.16 259 19.20k 0.00 239 19.20k 0.00 143 19.23k 0.16 103 57.6k 57.47k -0.22 86 57.60k 0.00 79 57.60k 0.00 47 57.14k -0.79 34 115.2k 116.3k 0.94 42 115.2k 0.00 39 115.2k 0.00 23 117.6k 2.12 16 baud rate sync = 0 , brgh = 1 , brg16 = 1 or sync = 1 , brg16 = 1 f osc = 4.000 mhz f osc = 3.6864 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) actual rate % error spbrg value (decimal) 300 300.0 0.01 3332 300.0 0.00 3071 299.9 -0.02 1666 300.1 0.04 832 1200 1200 0.04 832 1200 0.00 767 1199 -0.08 416 1202 0.16 207 2400 2398 0.08 416 2400 0.00 383 2404 0.16 207 2404 0.16 103 9600 9615 0.16 103 9600 0.00 95 9615 0.16 51 9615 0.16 25 10417 10417 0.00 95 10473 0.53 87 10417 0.00 47 10417 0.00 23 19.2k 19.23k 0.16 51 19.20k 0.00 47 19.23k 0.16 25 19.23k 0.16 12 57.6k 58.82k 2.12 16 57.60k 0.00 15 55.56k -3.55 8 ? ? ? 115.2k 111.1k -3.55 8 115.2k 0.00 7 ? ? ? ? ? ? table 12-5: baud rates for asynchronous modes (continued)
? 2007 microchip technology inc. preliminary ds41291d-page 165 pic16f822/883/884/886/887 12.3.1 a uto-baud detect the eusart module supports automatic detection and calibration of the baud rate. in the auto-baud detect (abd) mode, the clock to the brg is reversed. rather than the brg clocking the incoming rx signal, the rx signal is timing the brg. the baud rate generator is used to time the period of a received 55h (ascii ?u?) which is the sync character for the lin bus. the unique feature of this character is that it has five rising edges including the stop bit edge. setting the abden bit of the baudctl register starts the auto-baud calibration sequence (figure 12-6). while the abd sequence takes place, the eusart state machine is held in idle. on the first rising edge of the receive line, after the start bit, the spbrg begins counting up using the brg counter clock as shown in table 12-6. the fifth rising edge will occur on the rx pin at the end of the eighth bit period. at that time, an accumulated value totaling the proper brg period is left in spbrgh, spbrg register pair, the abden bit is automatically cleared and the rcif interrupt flag is set. the value in the rcreg needs to be read to clear the rcif interrupt. rcreg content should be discarded. when calibrating for modes that do not use the spbrgh register the user can verify that the spbrg register did not overflow by checking for 00h in the spbrgh register. the brg auto-baud clock is determined by the brg16 and brgh bits as shown in table 12-6. during abd, both the spbrgh and spbrg registers are used as a 16-bit counter, independent of the brg16 bit setting. while calibrating the baud rate period, the spbrgh and spbrg registers are clocked at 1/8th the brg base clock rate. the resulting byte measurement is the average bit time when clocked at full speed. table 12-6: brg counter clock rates figure 12-6: automatic baud rate calibration note 1: if the wue bit is set with the abden bit, auto-baud detection will occur on the byte following the break character (see section 12.3.2 ?auto-wake-up on break? ). 2: it is up to the user to determine that the incoming character baud rate is within the range of the selected brg clock source. some combinations of oscillator frequency and eusart baud rates are not possible due to bit error rates. overall system timing and communication baud rates must be taken into consideration when using the auto-baud detect feature. 3: after completion of the auto-baud sequence, the calculated auto-baud value will be the baud-rate plus 1. brg16 brgh brg base clock brg abd clock 00 f osc /64 f osc /512 01 f osc /16 f osc /128 10 f osc /16 f osc /128 11 f osc /4 f osc /32 note: during the abd sequence, spbrg and spbrgh registers are both used as a 16-bit counter, independent of brg16 setting. brg value rx pin abden bit rcif bit bit 0 bit 1 (interrupt) read rcreg brg clock start auto cleared set by user xxxxh 0000h edge #1 bit 2 bit 3 edge #2 bit 4 bit 5 edge #3 bit 6 bit 7 edge #4 stop bit edge #5 001ch note 1: the abd sequence requires the eusart module to be configured in asynchronous mode spbrg xxh 1ch spbrgh xxh 00h rcidl
pic16f822/883/884/886/887 ds41291d-page 166 preliminary ? 2007 microchip technology inc. 12.3.2 auto-wake-up on break during sleep mode, all clocks to the eusart are suspended. because of this, the baud rate generator is inactive and a proper character reception cannot be performed. the auto-wake-up feature allows the controller to wake-up due to activity on the rx/dt line. this feature is available only in asynchronous mode. the auto-wake-up feature is enabled by setting the wue bit of the baudctl register. once set, the normal receive sequence on rx/dt is disabled and the eusart remains in an idle state, monitoring for a wake- up event independent of the cpu mode. a wake-up event consists of a high-to-low transition on the rx/dt line. (this coincides with the start of a sync break or a wake-up signal character for the lin protocol.) the eusart module generates an rcif interrupt coincident with the wake-up event. the interrupt is generated synchronously to the q clocks in normal cpu operating modes (figure 12-7), and asynchronously if the device is in sleep mode (figure 12-8). the interrupt condition is cleared by reading the rcreg register. the wue bit is automatically cleared by the low-to-high transition on the rx line at the end of the break. this signals to the user that the break event is over. at this point, the eusart module is in idle mode waiting to receive the next character. 12.3.2.1 special considerations break character to avoid character errors or character fragments during a wake-up event, the wake-up character must be all zeros. when the wake-up is enabled the function works independent of the low time on the data stream. if the wue bit is set and a valid non-zero character is received, the low time from the start bit to the first rising edge will be interpreted as the wake-up event. the remaining bits in the character will be received as a fragmented character and subsequent characters can result in framing or overrun errors. therefore, the initial character in the transmission must be all ? 0 ?s. this must be 10 or more bit times, 13-bit times recommended for lin bus, or any number of bit times for standard rs-232 devices. oscillator startup time oscillator start-up time must be considered, especially in applications using oscillators with longer start-up intervals (i.e., lp, xt or hs/pll mode). the sync break (or wake-up signal) character must be of sufficient length, and be followed by a sufficient interval, to allow enough time for the selected oscillator to start and provide proper initialization of the eusart. wue bit the wake-up event causes a receive interrupt by setting the rcif bit. the wue bit is cleared in hardware by a rising edge on rx/dt. the interrupt condition is then cleared in software by reading the rcreg register and discarding its contents. to ensure that no actual data is lost, check the rcidl bit to verify that a receive operation is not in process before setting the wue bit. if a receive operation is not occurring, the wue bit may then be set just prior to entering the sleep mode. figure 12-7: auto-wake-up bit (wue) timing during no rmal operation q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 wue bit rx/dt line rcif bit set by user auto cleared cleared due to user read of rcreg note 1: the eusart remains in idle while the wue bit is set.
? 2007 microchip technology inc. preliminary ds41291d-page 167 pic16f822/883/884/886/887 figure 12-8: auto-wake-up bit (wue) timings during sleep 12.3.3 break character sequence the eusart module has the capability of sending the special break character sequences that are required by the lin bus standard. a break character consists of a start bit, followed by 12 ? 0 ? bits and a stop bit. to send a break character, set the sendb and txen bits of the txsta register. the break character trans- mission is then initiated by a write to the txreg. the value of data written to txreg will be ignored and all ? 0 ?s will be transmitted. the sendb bit is automatically reset by hardware after the corresponding stop bit is sent. this allows the user to preload the transmit fifo with the next transmit byte following the break character (typically, the sync character in the lin specification). the trmt bit of the txsta register indicates when the transmit operation is active or idle, just as it does during normal transmission. see figure 12-9 for the timing of the break character sequence. 12.3.3.1 break and sync transmit sequence the following sequence will start a message frame header made up of a break, followed by an auto-baud sync byte. this sequence is typical of a lin bus master. 1. configure the eusart for the desired mode. 2. set the txen and sendb bits to enable the break sequence. 3. load the txreg with a dummy character to initiate transmission (the value is ignored). 4. write ?55h? to txreg to load the sync character into the transmit fifo buffer. 5. after the break has been sent, the sendb bit is reset by hardware and the sync character is then transmitted. when the txreg becomes empty, as indicated by the txif, the next data byte can be written to txreg. 12.3.4 receiving a break character the enhanced eusart module can receive a break character in two ways. the first method to detect a break character uses the ferr bit of the rcsta register and the received data as indicated by rcreg. the baud rate generator is assumed to have been initialized to the expected baud rate. a break character has been received when: ? rcif bit is set ? ferr bit is set ? rcreg = 00h the second method uses the auto-wake-up feature described in section 12.3.2 ?auto-wake-up on break? . by enabling this feature, the eusart will sample the next two transitions on rx/dt, cause an rcif interrupt, and receive the next data byte followed by another interrupt. note that following a break character, the user will typically want to enable the auto-baud detect feature. for both methods, the user can set the abden bit of the baudctl register before placing the eusart in sleep mode. q1 q2 q3 q4 q1q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 wue bit rx/dt line rcif bit set by user auto cleared cleared due to user read of rcreg sleep command executed note 1 note 1: if the wake-up event requires long oscillator warm-up time, the automatic clearing of the wue bit can occur while the stposc signal is still active. this sequence should not depend on the presence of q clocks. 2: the eusart remains in idle while the wue bit is set. sleep ends
pic16f822/883/884/886/887 ds41291d-page 168 preliminary ? 2007 microchip technology inc. figure 12-9: send break character sequence write to txreg dummy write brg output (shift clock) start bit bit 0 bit 1 bit 11 stop bit break txif bit (transmit interrupt flag) tx (pin) trmt bit (transmit shift reg. empty flag) sendb (send break control bit) sendb sampled here auto cleared
? 2007 microchip technology inc. preliminary ds41291d-page 169 pic16f822/883/884/886/887 12.4 eusart synchronous mode synchronous serial communications are typically used in systems with a single master and one or more slaves. the master device contains the necessary cir- cuitry for baud rate generation and supplies the clock for all devices in the system. slave devices can take advantage of the master clock by eliminating the internal clock generation circuitry. there are two signal lines in synchronous mode: a bidi- rectional data line and a clock line. slaves use the external clock supplied by the master to shift the serial data into and out of their respective receive and trans- mit shift registers. since the data line is bidirectional, synchronous operation is half-duplex only. half-duplex refers to the fact that master and slave devices can receive and transmit data, but not both simultaneously. the eusart can operate as either a master or slave device. start and stop bits are not used in synchronous transmissions. 12.4.1 synchronous master mode the following bits are used to configure the eusart for synchronous master operation: ? sync = 1 ? csrc = 1 ? sren = 0 (for transmit); sren = 1 (for receive) ? cren = 0 (for transmit); cren = 1 (for receive) ? spen = 1 setting the sync bit of the txsta register configures the device for synchronous operation. setting the csrc bit of the txsta register configures the device as a master. clearing the sren and cren bits of the rcsta register ensures that the device is in the transmit mode, otherwise the device will be configured to receive. setting the spen bit of the rcsta register enables the eusart. if the rx/dt or tx/ck pins are shared with an analog peripheral the analog i/o functions must be disabled by clearing the corresponding ansel bits. 12.4.1.1 master clock synchronous data transfers use a separate clock line, which is synchronous with the data. a device config- ured as a master transmits the clock on the tx/ck line. the tx/ck pin is automatically configured as an output when the eusart is configured for synchronous transmit operation. serial data bits change on the lead- ing edge to ensure they are valid at the trailing edge of each clock. one clock cycle is generated for each data bit. only as many clock cycles are generated as there are data bits. 12.4.1.2 clock polarity a clock polarity option is provided for microwire compatability. clock polarity is selected with the sckp bit of the baudctl register. setting the sckp bit sets the clock idle state as high. when the sckp bit is set, the data changes on the falling edge of each clock. clearing the sckp bit sets the idle state as low. when the sckp bit is cleared, the data changes on the rising edge of each clock. 12.4.1.3 synchronous master transmission data is transferred out of the device on the rx/dt pin. the rx/dt and tx/ck pin output drivers are automat- ically enabled when the eusart is configured for synchronous master transmit operation. a transmission is initiated by writing a character to the txreg register. if the tsr still contains all or part of a previous character the new character data is held in the txreg until the last bit of the previous character has been transmitted. if this is the first character, or the pre- vious character has been completely flushed from the tsr, the data in the txreg is immediately transferred to the tsr. the transmission of the character commences immediately following the transfer of the data to the tsr from the txreg. each data bit changes on the leading edge of the master clock and remains valid until the subsequent leading clock edge. 12.4.1.4 synchronous master transmission set-up: 1. initialize the spbrgh, spbrg register pair and the brgh and brg16 bits to achieve the desired baud rate (see section 12.3 ?eusart baud rate generator (brg)? ). 2. enable the synchronous master serial port by setting bits sync, spen and csrc. 3. disable receive mode by clearing bits sren and cren. 4. enable transmit mode by setting the txen bit. 5. if 9-bit transmission is desired, set the tx9 bit. 6. if interrupts are desired, set the txie, gie and peie interrupt enable bits. 7. if 9-bit transmission is selected, the ninth bit should be loaded in the tx9d bit. 8. start transmission by loading data to the txreg register. note: the tsr register is not mapped in data memory, so it is not available to the user.
pic16f822/883/884/886/887 ds41291d-page 170 preliminary ? 2007 microchip technology inc. figure 12-10: synchronous transmission figure 12-11: synchronous transmis sion (through txen) table 12-7: registers associated with synchronous master transmission namebit 7bit 6bit 5bit 4bit 3bit 2bit 1bit 0 value on por, bor value on all other resets baudctl abdovf rcidl ? sckp brg16 ? wue abden 01-0 0-00 01-0 0-00 intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x pie1 ? adie rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 pir1 ? adif rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 rcreg eusart receive data register 0000 0000 0000 0000 rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x spbrg brg7 brg6 brg5 brg4 brg3 brg2 brg1 brg0 0000 0000 0000 0000 spbrgh brg15 brg14 brg13 brg12 brg11 brg10 brg9 brg8 0000 0000 0000 0000 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 1111 1111 1111 1111 txreg eusart transmit data register 0000 0000 0000 0000 txsta csrc tx9 txen sync sendb brgh trmt tx9d 0000 0010 0000 0010 legend: x = unknown, ? = unimplemented read as ? 0 ?. shaded cells are not used for synchronous master transmission. bit 0 bit 1 bit 7 word 1 bit 2 bit 0 bit 1 bit 7 rx/dt write to txreg reg txif bit (interrupt flag) txen bit ? 1 ? ? 1 ? word 2 trmt bit write word 1 write word 2 note: sync master mode, spbrg = 0 , continuous transmission of two 8-bit words. pin tx/ck pin tx/ck pin (sckp = 0 ) (sckp = 1 ) rx/dt pin tx/ck pin write to txreg reg txif bit trmt bit bit 0 bit 1 bit 2 bit 6 bit 7 txen bit
? 2007 microchip technology inc. preliminary ds41291d-page 171 pic16f822/883/884/886/887 12.4.1.5 synchronous master reception data is received at the rx/dt pin. the rx/dt and tx/ ck pin output drivers are automatically disabled when the eusart is configured for synchronous master receive operation. in synchronous mode, reception is enabled by setting either the single receive enable bit (sren of the rcsta register) or the continuous receive enable bit (cren of the rcsta register). when sren is set and cren is clear, only as many clock cycles are generated as there are data bits in a single character. the sren bit is automatically cleared at the completion of one character. when cren is set, clocks are continuously generated until cren is cleared. if cren is cleared in the middle of a character the ck clock stops immediately and the partial charac- ter is discarded. if sren and cren are both set, then sren is cleared at the completion of the first character and cren takes precedence. to initiate reception, set either sren or cren. data is sampled at the rx/dt pin on the trailing edge of the tx/ck clock pin and is shifted into the receive shift register (rsr). when a complete character is received into the rsr, the rcif bit is set and the char- acter is automatically transferred to the two character receive fifo. the least significant eight bits of the top character in the receive fifo are available in rcreg. the rcif bit remains set as long as there are un-read characters in the receive fifo. 12.4.1.6 receive overrun error the receive fifo buffer can hold two characters. an overrun error will be generated if a third character, in its entirety, is received before rcreg is read to access the fifo. when this happens the oerr bit of the rcsta register is set. previous data in the fifo will not be overwritten. the two characters in the fifo buffer can be read, however, no additional characters will be received until the error is cleared. the oerr bit can only be cleared by clearing the overrun condition. if the overrun error occurred when the sren bit is set and cren is clear then the error is cleared by reading rcreg. if the overrun occurred when the cren bit is set then the error condition is cleared by either clearing the cren bit of the rcsta register or by clearing the spen bit which resets the eusart. 12.4.1.7 receiving 9-bit characters the eusart supports 9-bit character reception. when the rx9 bit of the rcsta register is set the eusart will shift 9-bits into the rsr for each character received. the rx9d bit of the rcsta register is the ninth, and most significant, data bit of the top unread character in the receive fifo. when reading 9-bit data from the receive fifo buffer, the rx9d data bit must be read before reading the 8 least significant bits from the rcreg. 12.4.1.8 synchronous master reception set- up: 1. initialize the spbrgh, spbrg register pair for the appropriate baud rate. set or clear the brgh and brg16 bits, as required, to achieve the desired baud rate. 2. enable the synchronous master serial port by setting bits sync, spen and csrc. 3. ensure bits cren and sren are clear. 4. if using interrupts, set the gie and peie bits of the intcon register and set rcie. 5. if 9-bit reception is desired, set bit rx9. 6. start reception by setting the sren bit or for continuous reception, set the cren bit. 7. interrupt flag bit rcif will be set when reception of a character is complete. an interrupt will be generated if the enable bit rcie was set. 8. read the rcsta register to get the ninth bit (if enabled) and determine if any error occurred during reception. 9. read the 8-bit received data by reading the rcreg register. 10. if an overrun error occurs, clear the error by either clearing the cren bit of the rcsta register or by clearing the spen bit which resets the eusart.
pic16f822/883/884/886/887 ds41291d-page 172 preliminary ? 2007 microchip technology inc. figure 12-12: synchronous reception (master mode, sren) table 12-8: registers associated with synchronous master reception namebit 7bit 6bit 5bit 4bit 3bit 2bit 1bit 0 value on por, bor value on all other resets baudctl abdovf rcidl ? sckp brg16 ? wue abden 01-0 0-00 01-0 0-00 intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x pie1 ? adie rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 pir1 ? adif rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 rcreg eusart receive data register 0000 0000 0000 0000 rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x spbrg brg7 brg6 brg5 brg4 brg3 brg2 brg1 brg0 0000 0000 0000 0000 spbrgh brg15 brg14 brg13 brg12 brg11 brg10 brg9 brg8 0000 0000 0000 0000 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 1111 1111 1111 1111 txreg eusart transmit data register 0000 0000 0000 0000 txsta csrc tx9 txen sync sendb brgh trmt tx9d 0000 0010 0000 0010 legend: x = unknown, ? = unimplemented read as ? 0 ?. shaded cells are not used for synchronous master reception. cren bit rx/dt write to bit sren sren bit rcif bit (interrupt) read rxreg ? 0 ? bit 0 bit 1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7 ? 0 ? note: timing diagram demonstrates sync master mode with bit sren = 1 and bit brgh = 0 . tx/ck pin tx/ck pin pin (sckp = 0 ) (sckp = 1 )
? 2007 microchip technology inc. preliminary ds41291d-page 173 pic16f822/883/884/886/887 12.4.2 synchronous slave mode the following bits are used to configure the eusart for synchronous slave operation: ? sync = 1 ? csrc = 0 ? sren = 0 (for transmit); sren = 1 (for receive) ? cren = 0 (for transmit); cren = 1 (for receive) ? spen = 1 setting the sync bit of the txsta register configures the device for synchronous operation. clearing the csrc bit of the txsta register configures the device as a slave. clearing the sren and cren bits of the rcsta register ensures that the device is in the transmit mode, otherwise the device will be configured to receive. setting the spen bit of the rcsta register enables the eusart. if the rx/dt or tx/ck pins are shared with an analog peripheral the analog i/o functions must be disabled by clearing the corresponding ansel bits. 12.4.2.1 eusart synchronous slave transmit the operation of the synchronous master and slave modes are identical (see section 12.4.1.3 ?synchronous master transmission?) , except in the case of the sleep mode. if two words are written to the txreg and then the sleep instruction is executed, the following will occur: 1. the first character will immediately transfer to the tsr register and transmit. 2. the second word will remain in txreg register. 3. the txif bit will not be set. 4. after the first character has been shifted out of tsr, the txreg register will transfer the second character to the tsr and the txif bit will now be set. 5. if the peie and txie bits are set, the interrupt will wake the device from sleep and execute the next instruction. if the gie bit is also set, the program will call the interrupt service routine. 12.4.2.2 synchronous slave transmission set-up: 1. set the sync and spen bits and clear the csrc bit. 2. clear the cren and sren bits. 3. if using interrupts, ensure that the gie and peie bits of the intcon register are set and set the txie bit. 4. if 9-bit transmission is desired, set the tx9 bit. 5. enable transmission by setting the txen bit. 6. if 9-bit transmission is selected, insert the most significant bit into the tx9d bit. 7. start transmission by writing the least significant 8 bits to the txreg register. table 12-9: registers associated with synchronous slave transmission namebit 7bit 6bit 5bit 4bit 3bit 2bit 1bit 0 value on por, bor value on all other resets baudctl abdovf rcidl ?sckp brg16 ? wue abden 01-0 0-00 01-0 0-00 intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x pie1 ? adie rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 pir1 ? adif rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 rcreg eusart receive data register 0000 0000 0000 0000 rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x spbrg brg7 brg6 brg5 brg4 brg3 brg2 brg1 brg0 0000 0000 0000 0000 spbrgh brg15 brg14 brg13 brg12 brg11 brg10 brg9 brg8 0000 0000 0000 0000 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 1111 1111 1111 1111 txreg eusart transmit data register 0000 0000 0000 0000 txsta csrc tx9 txen sync sendb brgh trmt tx9d 0000 0010 0000 0010 legend: x = unknown, ? = unimplemented read as ? 0 ?. shaded cells are not used fo r synchronous slave transmission.
pic16f822/883/884/886/887 ds41291d-page 174 preliminary ? 2007 microchip technology inc. 12.4.2.3 eusart synchronous slave reception the operation of the synchronous master and slave modes is identical ( section 12.4.1.5 ?synchronous master reception? ), with the following exceptions: ? sleep ? cren bit is always set, therefore the receiver is never idle ? sren bit, which is a ?don?t care? in slave mode a character may be received while in sleep mode by setting the cren bit prior to entering sleep. once the word is received, the rsr register will transfer the data to the rcreg register. if the rcie enable bit is set, the interrupt generated will wake the device from sleep and execute the next instruction. if the gie bit is also set, the program will branch to the interrupt vector. 12.4.2.4 synchronous slave reception set- up: 1. set the sync and spen bits and clear the csrc bit. 2. if using interrupts, ensure that the gie and peie bits of the intcon register are set and set the rcie bit. 3. if 9-bit reception is desired, set the rx9 bit. 4. set the cren bit to enable reception. 5. the rcif bit will be set when reception is complete. an interrupt will be generated if the rcie bit was set. 6. if 9-bit mode is enabled, retrieve the most significant bit from the rx9d bit of the rcsta register. 7. retrieve the 8 least significant bits from the receive fifo by reading the rcreg register. 8. if an overrun error occurs, clear the error by either clearing the cren bit of the rcsta register or by clearing the spen bit which resets the eusart. table 12-10: registers associated with synchronous slave reception namebit 7bit 6bit 5bit 4bit 3bit 2bit 1bit 0 value on por, bor value on all other resets baudctl abdovf rcidl ?sckp brg16 ? wue abden 01-0 0-00 01-0 0-00 intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x pie1 ? adie rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 pir1 ? adif rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 rcreg eusart receive data register 0000 0000 0000 0000 rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 0000 000x spbrg brg7 brg6 brg5 brg4 brg3 brg2 brg1 brg0 0000 0000 0000 0000 spbrgh brg15 brg14 brg13 brg12 brg11 brg10 brg9 brg8 0000 0000 0000 0000 trisc trisc7 trisc6 trisc5 trisc4 trisc3 trisc2 trisc1 trisc0 1111 1111 1111 1111 txreg eusart transmit data register 0000 0000 0000 0000 txsta csrc tx9 txen sync sendb brgh trmt tx9d 0000 0010 0000 0010 legend: x = unknown, ? = unimplemented read as ? 0 ?. shaded cells are not used fo r synchronous slave reception.
? 2007 microchip technology inc. preliminary ds41291d-page 175 pic16f882/883/884/886/887 13.0 master synchronous serial port (mssp) module 13.1 master ssp (mssp) module overview the master synchronous serial port (mssp) module is a serial interface useful for communicating with other peripheral or microcontroller devices. these peripheral devices may be serial eeproms, shift registers, dis- play drivers, a/d converters, etc. the mssp module can operate in one of two modes: ? serial peripheral interface (spi) ? inter-integrated circuit tm (i 2 c tm ) - full master mode - slave mode (with general address call). the i 2 c interface supports the following modes in hardware: ?master mode ? multi-master mode ? slave mode. 13.2 control registers the mssp module has three associated registers. these include a status register and two control registers. register 13-1 shows the mssp status register (sspstat), register 13-2 shows the mssp control register 1 (sspcon), and register 13-3 shows the mssp control register 2 (sspcon2).
pic16f882/883/884/886/887 ds41291d-page 176 preliminary ? 2007 microchip technology inc. register 13-1: sspstat: ssp status register r/w-0 r/w-0 r-0 r-0 r-0 r-0 r-0 r-0 smp cke d/a psr/w ua bf bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 smp: sample bit spi master mode: 1 = input data sampled at end of data output time 0 = input data sampled at middle of data output time spi slave mode: smp must be cleared when spi is used in slave mode in i 2 c master or slave mode: 1 = slew rate control disabled for standard speed mode (100 khz and 1 mhz) 0 = slew rate control enabled for high speed mode (400 khz) bit 6 cke: spi clock edge select bit ckp = 0 : 1 = data transmitted on rising edge of sck 0 = data transmitted on falling edge of sck ckp = 1 : 1 = data transmitted on falling edge of sck 0 = data transmitted on rising edge of sck bit 5 d/a : data/address bit (i 2 c mode only) 1 = indicates that the last byte received or transmitted was data 0 = indicates that the last byte received or transmitted was address bit 4 p: stop bit (i 2 c mode only. this bit is cleared when the mssp module is disabled, sspen is cleared.) 1 = indicates that a stop bit has been detected last (this bit is ? 0 ? on reset) 0 = stop bit was not detected last bit 3 s: start bit (i 2 c mode only. this bit is cleared when the mssp module is disabled, sspen is cleared.) 1 = indicates that a start bit has been detected last (this bit is ? 0 ? on reset) 0 = start bit was not detected last bit 2 r/w : read/write bit information (i 2 c mode only) this bit holds the r/w bit information following the last address match. this bit is only valid from the address match to the next start bit, stop bit, or not ack bit. in i 2 c slave mode: 1 = read 0 = write in i 2 c master mode: 1 = transmit is in progress 0 = transmit is not in progress or-ing this bit with sen, rsen, pen, rcen, or acken will indicate if the mssp is in idle mode. bit 1 ua: update address bit (10-bit i 2 c mode only) 1 = indicates that the user needs to update the address in the sspadd register 0 = address does not need to be updated bit 0 bf: buffer full status bit receive (spi and i 2 c modes): 1 = receive complete, sspbuf is full 0 = receive not complete, sspbuf is empty transmit (i 2 c mode only): 1 = data transmit in progress (does not include the ack and stop bits), sspbuf is full 0 = data transmit complete (does not include the ack and stop bits), sspbuf is empty
? 2007 microchip technology inc. preliminary ds41291d-page 177 pic16f882/883/884/886/887 register 13-2: sspcon: ssp control register 1 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 wcol: write collision detect bit master mode: 1 = a write to the sspbuf register was attempted while the i 2 c conditions were not valid for a transmission to be started 0 = no collision slave mode: 1 = the sspbuf register is written while it is still trans mitting the previous word (m ust be cleared in software) 0 = no collision bit 6 sspov: receive overflow indicator bit in spi mode: 1 = a new byte is received while the sspbuf register is still holding the previous data. in case of overflow, the data in sspsr is lost. overflow can only occur in slave mode. in slave mode, the user must read the sspbuf, even if only transmitting data, to avoid setting overflow. in master mode, the overflow bit is not set since each new reception (and transmission) is initiated by writing to the sspbuf register (must be cleared in software). 0 = no overflow in i 2 c mode: 1 = a byte is received while the sspbuf register is still holding the previous byte. sspov is a ?don?t care? in transmit mode (must be cleared in software). 0 = no overflow bit 5 sspen: synchronous serial port enable bit in both modes, when enabled, these pins must be properly configured as input or output in spi mode: 1 = enables serial port and configures sck, sdo, sdi and ss as the source of the serial port pins 0 = disables serial port and configures these pins as i/o port pins in i 2 c mode: 1 = enables the serial port and confi gures the sda and scl pins as t he source of the serial port pins 0 = disables serial port and configures these pins as i/o port pins bit 4 ckp: clock polarity select bit in spi mode: 1 = idle state for clock is a high level 0 = idle state for clock is a low level in i 2 c slave mode: sck release control 1 = enable clock 0 = holds clock low (clock stretch). (used to ensure data setup time.) in i 2 c master mode: unused in this mode bit 3-0 sspm<3:0>: synchronous serial port mode select bits 0000 = spi master mode, clock = f osc /4 0001 = spi master mode, clock = f osc /16 0010 = spi master mode, clock = f osc /64 0011 = spi master mode, clock = tmr2 output/2 0100 = spi slave mode, clock = sck pin, ss pin control enabled 0101 = spi slave mode, clock = sck pin, ss pin control disabled, ss can be used as i/o pin 0110 = i 2 c slave mode, 7-bit address 0111 = i 2 c slave mode, 10-bit address 1000 = i 2 c master mode, clock = f osc / (4 * (sspadd+1)) 1001 = load mask function 1010 = reserved 1011 = i 2 c firmware controlled master mode (slave idle) 1100 = reserved 1101 = reserved 1110 = i 2 c slave mode, 7-bit address with start and stop bit interrupts enabled 1111 = i 2 c slave mode, 10-bit address with start and stop bit interrupts enabled
pic16f882/883/884/886/887 ds41291d-page 178 preliminary ? 2007 microchip technology inc. register 13-3: sspcon2: ssp control register 2 r/w-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 gcen ackstat ackdt acken rcen pen rsen sen bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 gcen: general call enable bit (in i 2 c slave mode only) 1 = enable interrupt when a general call address (0000h) is received in the sspsr 0 = general call address disabled bit 6 ackstat: acknowledge status bit (in i 2 c master mode only) in master transmit mode: 1 = acknowledge was not received from slave 0 = acknowledge was received from slave bit 5 ackdt: acknowledge data bit (in i 2 c master mode only) in master receive mode: value transmitted when the user initiates an acknowledge sequence at the end of a receive 1 = not acknowledge 0 = acknowledge bit 4 acken: acknowledge sequence enable bit (in i 2 c master mode only) in master receive mode: 1 = initiate acknowledge sequence on sda and scl pins, and transmit ackdt data bit. automatically cleared by hardware. 0 = acknowledge sequence idle bit 3 rcen: receive enable bit (in i 2 c master mode only) 1 = enables receive mode for i 2 c 0 = receive idle bit 2 pen: stop condition enable bit (in i 2 c master mode only) sck release control: 1 = initiate stop condition on sda and scl pins. automatically cleared by hardware. 0 = stop condition idle bit 1 rsen: repeated start condition enabled bit (in i 2 c master mode only) 1 = initiate repeated start condition on sda and scl pins. automatically cleared by hardware. 0 = repeated start condition idle bit 0 sen: start condition enabled bit (in i 2 c master mode only) 1 = initiate start condition on sda and scl pins. automatically cleared by hardware. 0 = start condition idle note 1: for bits acken, rcen, pen, rsen, sen: if the i 2 c module is not in the idle mode, this bit may not be set (no spooling) and the sspbuf may not be written (or writes to the sspbuf are disabled).
? 2007 microchip technology inc. preliminary ds41291d-page 179 pic16f882/883/884/886/887 13.3 spi mode the spi mode allows 8 bits of data to be synchronously transmitted and received, simultaneously. all four modes of spi are supported. to accomplish communication, typically three pins are used: ? serial data out (sdo) ? rc5/sdo ? serial data in (sdi) ? rc4/sdi/sda ? serial clock (sck) ? rc3/sck/scl additionally, a fourth pin may be used when in any slave mode of operation: ? slave select (ss ) ? ra5/ss /an4 13.3.1 operation when initializing the spi, several options need to be specified. this is done by programming the appropriate control bits sspcon<5:0> and sspstat<7:6>. these control bits allow the following to be specified: ? master mode (sck is the clock output) ? slave mode (sck is the clock input) ? clock polarity (idle state of sck) ? data input sample phase (middle or end of data output time) ? clock edge (output data on rising/falling edge of sck) ? clock rate (master mode only) ? slave select mode (slave mode only) figure 13-1 shows the block diagram of the mssp module, when in spi mode. figure 13-1: mssp block diagram (spi mode) the mssp consists of a transmit/receive shift register (sspsr) and a buffer register (sspbuf). the sspsr shifts the data in and out of the device, msb first. the sspbuf holds the data that was written to the sspsr, until the received data is ready. once the 8 bits of data have been received, that byte is moved to the sspbuf register. then, the buffer full-detect bit bf of the ssp- stat register and the interrupt flag bit sspif of the pir1 register are set. this double buffering of the received data (sspbuf) allows the next byte to start reception before reading the data that was just received. any write to the sspbuf register during transmission/reception of data will be ignored, and the write collision detect bit wcol of the sspcon register will be set. user software must clear the wcol bit so that it can be determined if the following write(s) to the sspbuf register completed successfully. ( ) read write internal data bus sspsr reg sspm<3:0> bit 0 shift clock ss control enable edge select clock select tmr2 output t osc prescaler 4, 16, 64 2 edge select 2 4 data to tx/rx in sspsr tris bit 2 smp:cke sdi sdo ss sck note: i/o pins have diode protection to v dd and v ss . sspbuf reg
pic16f882/883/884/886/887 ds41291d-page 180 preliminary ? 2007 microchip technology inc. when the application software is expecting to receive valid data, the sspbuf should be read before the next byte of data to transfer is written to the sspbuf. the buffer full bit bf of the sspstat register indicates when sspbuf has been loaded with the received data (transmission is complete). when the sspbuf is read, the bf bit is cleared. this data may be irrelevant if the spi is only a transmitter. generally, the mssp interrupt is used to determine when the transmission/reception has completed. the sspbuf must be read and/or written. if the interrupt method is not going to be used, then software polling can be done to ensure that a write collision does not occur. example 13-1 shows the loading of the sspbuf (sspsr) for data transmission. the sspsr is not directly readable or writable, and can only be accessed by addressing the sspbuf register. additionally, the mssp status register (sspstat register) indicates the various status conditions. 13.3.2 enabling spi i/o to enable the serial port, ssp enable bit sspen of the sspcon register must be set. to reset or reconfigure spi mode, clear the sspen bit, re-initialize the sspcon registers, and then set the sspen bit. this configures the sdi, sdo, sck and ss pins as serial port pins. for the pins to behave as the serial port function, some must have their data direction bits (in the tris register) appropriately programmed. that is: ? sdi is automatically controlled by the spi module ? sdo must have trisc<5> bit cleared ? sck (master mode) must have trisc<3> bit cleared ? sck (slave mode) must have trisc<3> bit set ?ss must have trisa<5> bit set any serial port function that is not desired may be overridden by programming the corresponding data direction (tris) register to the opposite value. example 13-1: loading the sspbuf (sspsr) register loop btfss sspstat, bf ;has data been received (transmit complete)? goto loop ;no movf sspbuf, w ;wreg reg = contents of sspbuf movwf rxdata ;save in user ram, if data is meaningful movf txdata, w ;w reg = contents of txdata movwf sspbuf ;new data to xmit
? 2007 microchip technology inc. preliminary ds41291d-page 181 pic16f882/883/884/886/887 13.3.3 master mode the master can initiate the data transfer at any time because it controls the sck. the master determines when the slave is to broadcast data by the software protocol. in master mode, the data is transmitted/received as soon as the sspbuf register is written to. if the spi is only going to receive, the sdo output could be dis- abled (programmed as an input). the sspsr register will continue to shift in the signal present on the sdi pin at the programmed clock rate. as each byte is received, it will be loaded into the sspbuf register as a normal received byte (interrupts and status bits appropriately set). this could be useful in receiver applications as a ?line activity monitor? mode. the clock polarity is selected by appropriately program- ming the ckp bit of the sspcon register. this, then, would give waveforms for spi communication as shown in figure 13-2, figure 13-4 and figure 13-5, where the msb is transmitted first. in master mode, the spi clock rate (bit rate) is user programmable to be one of the following: ?f osc /4 (or t cy ) ?f osc /16 (or 4 ? t cy ) ?f osc /64 (or 16 ? t cy ) ? timer2 output/2 this allows a maximum data rate (at 40 mhz) of 10.00 mbps. figure 13-2 shows the waveforms for master mode. when the cke bit of the sspstat register is set, the sdo data is valid before there is a clock edge on sck. the change of the input sample is shown based on the state of the smp bit of the sspstat register. the time when the sspbuf is loaded with the received data is shown. figure 13-2: spi mode waveform (master mode) sck (ckp = 0 sck (ckp = 1 sck (ckp = 0 sck (ckp = 1 4 clock modes input sample input sample sdi bit 7 bit 0 sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit7 bit 0 sdi sspif (smp = 1 ) (smp = 0 ) (smp = 1 ) cke = 1 ) cke = 0 ) cke = 1 ) cke = 0 ) (smp = 0 ) write to sspbuf sspsr to sspbuf sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 (cke = 0 ) (cke = 1 ) next q4 cycle after q2
pic16f882/883/884/886/887 ds41291d-page 182 preliminary ? 2007 microchip technology inc. 13.3.4 slave mode in slave mode, the data is transmitted and received as the external clock pulses appear on sck. when the last bit is latched, the sspif interrupt flag bit of the pir1 register is set. while in slave mode, the external clock is supplied by the external clock source on the sck pin. this external clock must meet the minimum high and low times, as specified in the electrical specifications. while in sleep mode, the slave can transmit/receive data. when a byte is received, the device will wake-up from sleep. 13.3.5 slave select synchronization the ss pin allows a synchronous slave mode. the spi must be in slave mode with ss pin control enabled (sspcon<3:0> = 04h). the pin must not be driven low for the ss pin to function as an input. the data latch must be high. when the ss pin is low, transmission and reception are enabled and the sdo pin is driven. when the ss pin goes high, the sdo pin is no longer driven, even if in the mid- dle of a transmitted byte, and becomes a floating output. external pull-up/pull-down resistors may be desirable, depending on the application. when the spi module resets, the bit counter is forced to ? 0 ?. this can be done by either forcing the ss pin to a high level, or clearing the sspen bit. to emulate two-wire communication, the sdo pin can be connected to the sdi pin. when the spi needs to operate as a receiver, the sdo pin can be configured as an input. this disables transmissions from the sdo. the sdi can always be left as an input (sdi function), since it cannot create a bus conflict. figure 13-3: slave synchronization waveform note 1: when the spi is in slave mode with ss pin control enabled (sspcon<3:0> = 0100 ), the spi module will reset if the ss pin is set to v dd . 2: if the spi is used in slave mode with cke set (sspstat register), then the ss pin control must be enabled. sck (ckp = 1 sck (ckp = 0 input sampl e sdi bit 7 sdo bit 7 bit 6 bit 7 sspif (smp = 0 ) cke = 0 ) cke = 0 ) (smp = 0 ) write to sspbuf sspsr to sspbuf ss bit 0 bit 7 bit 0 next q4 cycle after q2
? 2007 microchip technology inc. preliminary ds41291d-page 183 pic16f882/883/884/886/887 figure 13-4: spi mode waveform (slave mode with cke = 0 ) figure 13-5: spi mode waveform (slave mode with cke = 1 ) sck (ckp = 1 sck (ckp = 0 input sample sdi bit 7 bit 0 sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 sspif (smp = 0 ) cke = 0 ) cke = 0 ) (smp = 0 ) write to sspbuf sspsr to sspbuf ss optional next q4 cycle after q2 sck (ckp = 1 sck (ckp = 0 input sample sdi bit 7 bit 0 sdo bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 sspif (smp = 0 ) cke = 1 ) cke = 1 ) (smp = 0 ) write to sspbuf sspsr to sspbuf ss required next q4 cycle after q2
pic16f882/883/884/886/887 ds41291d-page 184 preliminary ? 2007 microchip technology inc. 13.3.6 sleep operation in master mode, all module clocks are halted, and the transmission/reception will remain in that state until the device wakes from sleep. after the device returns to normal mode, the module will continue to transmit/receive data. in slave mode, the spi transmit/receive shift register operates asynchronously to the device. this allows the device to be placed in sleep mode and data to be shifted into the spi transmit/receive shift register. when all eight bits have been received, the mssp interrupt flag bit will be set and, if enabled, will wake the device from sleep. 13.3.7 effects of a reset a reset disables the mssp module and terminates the current transfer. 13.3.8 bus mode compatibility table 13-1 shows the compatibility between the standard spi modes and the states of the ckp and cke control bits. table 13-1: spi bus modes there is also a smp bit that controls when the data will be sampled. table 13-2: registers associated with spi operation standard spi mode terminology control bits state ckp cke 0 , 001 0 , 100 1 , 011 1 , 110 name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets intcon gie/gieh peie/giel t0ie inte rbie t0if intf rbif 0000 000x 0000 000u pie1 ? adie rcie txie sspie ccp1ie tmr2ie tmr1ie 0000 0000 0000 0000 pir1 ? adif rcif txif sspif ccp1if tmr2if tmr1if -000 0000 0000 0000 sspbuf synchronous serial port receive buffer/transmit register xxxx xxxx uuuu uuuu sspcon wcol sspov sspen ckp sspm3 sspm2 sspm1 sspm0 0000 0000 0000 0000 sspstat smp cke d/a p s r/w ua bf 0000 0000 0000 0000 trisa trisa7 trisa6 trisa5 trisa4 trisa3 trisa2 trisa1 trisa0 1111 1111 1111 1111 trisc trisc7 trisc6 trisc5 trisc 4 trisc3 trisc2 trisc1 trisc0 1111 1111 1111 1111 legend: x = unknown, u = unchanged, ? = unimplemented, read as ? 0 ?. shaded cells are not used by the mssp in spi mode. note 1: bit 6 of porta, lata and trisa are enabled in ecio and rcio oscillator modes only. in all other oscillator modes, they are disa bled and read ? 0 ?.
? 2007 microchip technology inc. preliminary ds41291d-page 185 pic16f882/883/884/886/887 13.4 mssp i 2 c operation the mssp module in i 2 c mode, fully implements all master and slave functions (including general call support) and provides interrupts on start and stop bits in hardware, to determine a fr ee bus (multi-master mode). the mssp module implements the standard mode specifications, as well as 7-bit and 10-bit addressing. two pins are used for data transfer. these are the rc3/sck/scl pin, which is the clock (scl), and the rc4/sdi/sda pin, which is the data (sda). the user must configure these pins as inputs or outputs through the trisc<4:3> bits. the mssp module functions are enabled by setting mssp enable bit sspen of the sspcon register. figure 13-6: mssp block diagram (i 2 c mode) the mssp module has these six registers for i 2 c operation: ? mssp control register 1 (sspcon) ? mssp control register 2 (sspcon2) ? mssp status register (sspstat) ? serial receive/transmit buffer (sspbuf) ? mssp shift register (sspsr) ? not directly accessible ? mssp address register (sspadd) ? mssp mask register (sspmsk) the sspcon register allows control of the i 2 c operation. the sspm<3:0> mode selection bits (sspcon register) allow one of the following i 2 c modes to be selected: ?i 2 c master mode, clock = osc/4 (sspadd +1) ?i 2 c slave mode (7-bit address) ?i 2 c slave mode (10-bit address) ?i 2 c slave mode (7-bit address), with start and stop bit interrupts enabled ?i 2 c slave mode (10-bit address), with start and stop bit interrupts enabled ?i 2 c firmware controlled master operation, slave is idle selection of any i 2 c mode with the sspen bit set, forces the scl and sda pins to be open drain, provided these pins are programmed to be inputs by setting the appropriate trisc bits. 13.4.1 slave mode in slave mode, the scl and sda pins must be configured as inputs (trisc<4:3> set). the mssp module will override the input state with the output data when required (slave-transmitter). when an address is matched, or the data transfer after an address match is received, the hardware automatically will generate the acknowledge (ack ) pulse and load the sspbuf register with the received value currently in the sspsr register. if either or both of the following conditions are true, the mssp module will not give this ack pulse: a) the buffer full bit bf (sspcon register) was set before the transfer was received. b) the overflow bit sspov (sspcon register) was set before the transfer was received. in this event, the sspsr register value is not loaded into the sspbuf, but bit sspif of the pir1 register is set. the bf bit is cleared by reading the sspbuf register, while bit sspov is cleared through software. the scl clock input must have a minimum high and low for proper operation. the high and low times of the i 2 c specification, as well as the requirement of the mssp module, are shown in timing parameter #100 and parameter #101. read write sspsr reg match detect sspadd reg start and stop bit detect sspbuf reg internal data bus addr match set, reset s, p bits (sspstat reg) rc3/sck/scl rc4/ shift clock msb sdi/ lsb sda note: i/o pins have diode protection to v dd and v ss . sspmsk reg
pic16f882/883/884/886/887 ds41291d-page 186 preliminary ? 2007 microchip technology inc. 13.4.1.1 addressing once the mssp module has been enabled, it waits for a start condition to occur. following the start condition, the eight bits are shifted into the sspsr register. all incoming bits are sampled with the rising edge of the clock (scl) line. the value of register sspsr<7:1> is compared to the value of the sspadd register. the address is compared on the falling edge of the eighth clock (scl) pulse. if the addresses match, and the bf and sspov bits are clear, the following events occur: a) the sspsr register value is loaded into the sspbuf register. b) the buffer full bit bf is set. c) an ack pulse is generated. d) mssp interrupt flag bit, sspif of the pir1 register, is set on the falling edge of the ninth scl pulse (interrupt is generated, if enabled). in 10-bit address mode, two address bytes need to be received by the slave. the five most significant bits (msb) of the first address byte specify if this is a 10-bit address. the r/w bit (sspstat register) must specify a write so the slave device will receive the second address byte. for a 10-bit address, the first byte would equal ?1111 0 a9 a8 0? , where a9 and a8 are the two msb?s of the address. the sequence of events for 10-bit addressing is as follows, with steps 7-9 for slave-transmitter: 1. receive first (high) byte of address (bit sspif of the pir1 register and bits bf and ua of the sspstat register are set). 2. update the sspadd register with second (low) byte of address (clears bit ua and releases the scl line). 3. read the sspbuf register (clears bit bf) and clear flag bit sspif. 4. receive second (low) byte of address (bits sspif, bf, and ua are set). 5. update the sspadd register with the first (high) byte of address. if match releases scl line, this will clear bit ua. 6. read the sspbuf register (clears bit bf) and clear flag bit sspif. 7. receive repeated start condition. 8. receive first (high) byte of address (bits sspif and bf are set). 9. read the sspbuf register (clears bit bf) and clear flag bit sspif. 13.4.1.2 reception when the r/w bit of the address byte is clear and an address match occurs, the r/w bit of the sspstat register is cleared. the received address is loaded into the sspbuf register. when the address byte overflow condition exists, then no acknowledge (ack ) pulse is given. an overflow condition is defined as either bit bf (sspstat register) is set, or bit sspov (sspcon register) is set. an mssp interrupt is generated for each data transfer byte. flag bit sspif of the pir1 register must be cleared in software. the sspstat register is used to determine the status of the byte. 13.4.1.3 transmission when the r/w bit of the incoming address byte is set and an address match occurs, the r/w bit of the sspstat register is set. the received address is loaded into the sspbuf register. the ack pulse will be sent on the ninth bit and pin rc3/sck/scl is held low. the transmit data must be loaded into the sspbuf register, which also loads the sspsr regis- ter. then pin rc3/sck/scl should be enabled by set- ting bit ckp (sspcon register). the master must monitor the scl pin prior to asserting another clock pulse. the slave devices may be holding off the master by stretching the clock. the eight data bits are shifted out on the falling edge of the scl input. this ensures that the sda signal is valid during the scl high time (figure 13-8). an mssp interrupt is generated for each data transfer byte. the sspif bit must be cleared in software and the sspstat register is used to determine the status of the byte. the sspif bit is set on the falling edge of the ninth clock pulse. as a slave-transmitter, the ack pulse from the master-receiver is latched on the rising edge of the ninth scl input pulse. if the sda line is high (not ack ), then the data transfer is complete. when the ack is latched by the slave, the slave logic is reset and the slave monitors for another occurrence of the start bit. if the sda line was low (ack ), the transmit data must be loaded into the sspbuf register, which also loads the sspsr register. pin rc3/sck/scl should be enabled by setting bit ckp.
? 2007 microchip technology inc. preliminary ds41291d-page 187 pic16f882/883/884/886/887 figure 13-7: i 2 c? slave mode waveforms for reception (7-bit address) figure 13-8: i 2 c? slave mode waveforms for transmission (7-bit address) p 9 8 7 6 5 d0 d1 d2 d3 d4 d5 d6 d7 s a7 a6 a5 a4 a3 a2 a1 sda scl 123456 789 1234 56 7 89 1234 bus master term ina tes transfer bit sspov is set because the sspbuf register is still full cleared in software sspbuf register is read ack receiving data receiving data d0 d1 d2 d3 d4 d5 d6 d7 ack r/w = 0 receiving address sspif bf sspov not ack ack is not sent sda scl sspif bf ckp a7 a6 a5 a4 a3 a2 a1 ack d7 d6 d5 d4 d3 d2 d1 d0 not ack transmitting data r/w = 1 receiving address 123456789 123456789 p cleared in software sspbuf is written in software from ssp interrupt service routine set bit after writing to sspbuf s data in sampled (the sspbuf must be written to before the ckp bit can be set) r/w = 0 responds to sspif scl held low while cpu
pic16f882/883/884/886/887 ds41291d-page 188 preliminary ? 2007 microchip technology inc. 13.4.2 general call address support the addressing procedure for the i 2 c bus is such that, the first byte after the start condition usually deter- mines which device will be the slave addressed by the master. the exception is the general call address, which can address all devices. when this address is used, all devices should, in theory, respond with an acknowledge. the general call address is one of eight addresses reserved for specific purposes by the i 2 c protocol. it consists of all 0 ?s with r/w = 0 . the general call address is recognized (enabled) when the general call enable (gce n) bit is set (sspcon2 register). following a start bit detect, eight bits are shifted into the sspsr and the address is compared against the sspadd. it is also compared to the general call address and fixed in hardware. if the general call address matches, the sspsr is transferred to the sspbuf, the bf bit is set (eighth bit), and on the falling edge of the ninth bit (ack bit), the sspif interrupt flag bit is set. when the interrupt is serviced, the source for the inter- rupt can be checked by reading the contents of the sspbuf. the value can be used to determine if the address was device specific or a general call address. in 10-bit mode, the sspadd is required to be updated for the second half of the address to match, and the ua bit is set (sspstat register). if the general call address is sampled when the gcen bit is set, and while the slave is configured in 10-bit address mode, then the second half of the address is not necessary. the ua bit will not be set, and the slave will begin receiving data after the acknowledge (figure 13-9). figure 13-9: slave mode general call address sequence (7 or 10-bit address) sda scl s sspif bf sspov cleared in software sspbuf is read r/w = 0 ack general call address address is compared to general call address gcen receiving data ack 123456789123456789 d7 d6 d5 d4 d3 d2 d1 d0 after ack, set interrupt ? 0 ? ? 1 ?
? 2007 microchip technology inc. preliminary ds41291d-page 189 pic16f882/883/884/886/887 13.4.3 master mode master mode of operation is supported by interrupt generation on the detection of the start and stop conditions. the stop (p) and start (s) bits are cleared from a reset, or when the mssp module is disabled. control of the i 2 c bus may be taken when the p bit is set, or the bus is idle, with both the s and p bits clear. in master mode, the scl and sda lines are manipu- lated by the mssp hardware. the following events will cause ssp interrupt flag bit, sspif, to be set (ssp interrupt if enabled): ? start condition ? stop condition ? data transfer byte transmitted/received ? acknowledge transmit ? repeated start condition 13.4.4 i 2 c? master mode support master mode is enabled by setting and clearing the appropriate sspm bits in sspcon and by setting the sspen bit. once master mode is enabled, the user has the following six options: 1. assert a start condition on sda and scl. 2. assert a repeated start condition on sda and scl. 3. write to the sspbuf register initiating transmission of data/address. 4. generate a stop condition on sda and scl. 5. configure the i 2 c port to receive data. 6. generate an acknowledge condition at the end of a received byte of data. figure 13-10: mssp block diagram (i 2 c? master mode) note: the mssp module, when configured in i 2 c master mode, does not allow queueing of events. for instance, the user is not allowed to initiate a start condition and immediately write the sspbuf register to imitate transmission, before the start condition is complete. in this case, the sspbuf will not be written to and the wcol bit will be set, indicating that a write to the sspbuf did not occur. read write sspsr start bit, stop bit, sspbuf internal data bus set/reset, s, p, wcol (sspstat) shift clock msb lsb sda acknowledge generate scl scl in bus collision sda in receive enable clock cntl clock arbitrate/wcol detect (hold off clock source) sspadd<6:0> baud set sspif, bclif reset ackstat, pen (sspcon2) rate generator sspm<3:0> note: i/o pins have diode protection to v dd and v ss . start bit detect stop bit detect write collision detect clock arbitration state counter for end of xmit/rcv
pic16f882/883/884/886/887 ds41291d-page 190 preliminary ? 2007 microchip technology inc. 13.4.4.1 i 2 c? master mode operation the master device generates all of the serial clock pulses and the start and stop conditions. a transfer is ended with a stop condition or with a repeated start condition. since the repeated start condition is also the beginning of the next serial transfer, the i 2 c bus will not be released. in master transmitter mode, serial data is output through sda, while scl outputs the serial clock. the first byte transmitted contains the slave address of the receiving device (7 bits) and the read/write (r/w ) bit. in this case, the r/w bit will be logic ? 0 ?. serial data is transmitted eight bits at a time. after each byte is trans- mitted, an acknowledge bit is received. start and stop conditions are output to indicate the beginning and the end of a serial transfer. in master receive mode, the first byte transmitted con- tains the slave address of the transmitting device (7 bits) and the r/w bit. in this case, the r/w bit will be logic ? 1 ?. thus, the first byte transmitted is a 7-bit slave address followed by a ? 1 ? to indicate receive bit. serial data is received via sda, while scl outputs the serial clock. serial data is received eight bits at a time. after each byte is received, an acknowledge bit is transmit- ted. start and stop conditions indicate the beginning and end of transmission. the baud rate generator used for the spi mode oper- ation is now used to set the scl clock frequency for either 100 khz, 400 khz, or 1 mhz i 2 c operation. the baud rate generator reload value is contained in the lower 7 bits of the sspadd register. the baud rate generator will automatically begin counting on a write to the sspbuf. once the given operation is complete (i.e., transmission of the last data bit is followed by ack), the internal clock will automatically stop counting and the scl pin will remain in its last state. a typical transmit sequence would go as follows: a) the user generates a start condition by setting the start enable (sen) bit (sspcon2 register). b) sspif is set. the mssp module will wait the required start time before any other operation takes place. c) the user loads the sspbuf with the address to transmit. d) address is shifted out the sda pin until all eight bits are transmitted. e) the mssp module shifts in the ack bit from the slave device and writes its value into the ackstat bit (sspcon2 register). f) the mssp module generates an interrupt at the end of the ninth clock cycle by setting the sspif bit. g) the user loads the sspbuf with eight bits of data. h) data is shifted out the sda pin until all eight bits are transmitted. i) the mssp module shifts in the ack bit from the slave device and writes its value into the ackstat bit (sspcon2 register). j) the mssp module generates an interrupt at the end of the ninth clock cycle by setting the sspif bit. k) the user generates a stop condition by setting the stop enable bit pen (sspcon2 register). l) interrupt is generated once the stop condition is complete.
? 2007 microchip technology inc. preliminary ds41291d-page 191 pic16f882/883/884/886/887 13.4.5 baud rate generator in i 2 c master mode, the reload value for the brg is located in the lower 7 bits of the sspadd register (figure 13-11). when the brg is loaded with this value, the brg counts down to 0 and stops until another reload has taken place. the brg count is decremented twice per instruction cycle (t cy ) on the q2 and q4 clocks. in i 2 c master mode, the brg is reloaded automatically. if clock arbitration is taking place, for instance, the brg will be reloaded when the scl pin is sampled high (figure 13-12). figure 13-11: baud rate generator block diagram figure 13-12: baud rate generator timing with clock arbitration sspm<3:0> brg down counter clkout f osc /4 sspadd<6:0> sspm<3:0> scl reload control reload sda scl scl de-asserted but slave holds dx-1 dx brg scl is sampled high, reload takes place and brg starts its count 03h 02h 01h 00h (hold off) 03h 02h reload brg value scl low (clock arbitration) scl allowed to transition high brg decrements on q2 and q4 cycles
pic16f882/883/884/886/887 ds41291d-page 192 preliminary ? 2007 microchip technology inc. 13.4.6 i 2 c? master mode start condition timing to initiate a start condition, the user sets the start con- dition enable bit sen of the sspcon2 register. if the sda and scl pins are sampled high, the baud rate generator is reloaded with the contents of sspadd<6:0> and starts its count. if scl and sda are both sampled high when the baud rate generator times out (t brg ), the sda pin is driven low. the action of the sda being driven low, while scl is high, is the start condition, and causes the s bit of the sspstat register to be set. following this, the baud rate gener- ator is reloaded with the contents of sspadd<6:0> and resumes its count. when the baud rate generator times out (t brg ), the sen bit of the sspcon2 register will be automatically cleared by hardware, the baud rate generator is suspended leaving the sda line held low and the start condition is complete. 13.4.6.1 wcol status flag if the user writes the sspbuf when a start sequence is in progress, the wcol is set and the contents of the buffer are unchanged (the write doesn?t occur). figure 13-13: first start bit timing note: if, at the beginning of the start condition, the sda and scl pins are already sam- pled low, or if during the start condition the scl line is sampled low before the sda line is driven low, a bus collision occurs, the bus collision interrupt flag, bclif, is set, the start condition is aborted, and the i 2 c module is reset into its idle state. note: because queueing of events is not allowed, writing to the lower 5 bits of sspcon2 is disabled until the start condi- tion is complete. sda scl s t brg 1st bit 2nd bit t brg sda = 1 , at completion of start bit, scl = 1 write to sspbuf occurs here t brg hardware clears sen bit t brg write to sen bit occurs here set s bit (sspstat) and sets sspif bit
? 2007 microchip technology inc. preliminary ds41291d-page 193 pic16f882/883/884/886/887 13.4.7 i 2 c? master mode repeated start condition timing a repeated start condition occurs when the rsen bit (sspcon2 register) is programmed high and the i 2 c logic module is in the idle state. when the rsen bit is set, the scl pin is asserted low. when the scl pin is sampled low, the baud rate generator is loaded with the contents of sspadd<5:0> and begins counting. the sda pin is released (brought high) for one baud rate generator count (t brg ). when the baud rate generator times out, if sda is sampled high, the scl pin will be de-asserted (brought high). when scl is sampled high, the baud rate generator is reloaded with the contents of sspadd<6:0> and begins count- ing. sda and scl must be sampled high for one t brg . this action is then followed by assertion of the sda pin (sda = 0) for one t brg , while scl is high. following this, the rsen bit (sspcon2 register) will be automat- ically cleared and the baud rate generator will not be reloaded, leaving the sda pin held low. as soon as a start condition is detected on the sda and scl pins, the s bit (sspstat register) will be set. the sspif bit will not be set until the baud rate generator has timed out. immediately following the sspif bit getting set, the user may write the sspbuf with the 7-bit address in 7-bit mode, or the default first address in 10-bit mode. after the first eight bits are transmitted and an ack is received, the user may then transmit an additional eight bits of address (10-bit mode), or eight bits of data (7-bit mode). 13.4.7.1 wcol status flag if the user writes the sspbuf when a repeated start sequence is in progress, the wcol is set and the con- tents of the buffer are unchanged (the write doesn?t occur). figure 13-14: repeat start condition waveform note 1: if rsen is programmed while any other event is in progress, it will not take effect. 2: a bus collision during the repeated start condition occurs if: ? sda is sampled low when scl goes from low-to-high. ? scl goes low before sda is asserted low. this may indicate that another master is attempting to transmit a data ? 1 ?. note: because queueing of events is not allowed, writing of the lower 5 bits of sspcon2 is disabled until the repeated start condition is complete. sda scl sr = repeated start write to sspcon2 write to sspbuf occurs here falling edge of ninth clock end of xmit at completion of start bit, hardware clear rsen bit 1st bit set s (sspstat<3>) t brg t brg sda = 1 , sda = 1 , scl (no change) scl = 1 occurs here, t brg t brg t brg and set sspif
pic16f882/883/884/886/887 ds41291d-page 194 preliminary ? 2007 microchip technology inc. 13.4.8 i 2 c? master mode transmission transmission of a data byte, a 7-bit address, or the other half of a 10-bit address, is accomplished by sim- ply writing a value to the sspbuf register. this action will set the buffer full bit, bf, and allow the baud rate generator to begin counting and start the next trans- mission. each bit of address/data will be shifted out onto the sda pin after the falling edge of scl is asserted (see data hold time specification, parameter 106). scl is held low for one baud rate generator roll- over count (t brg ). data should be valid before scl is released high (see data setup time specification, parameter 107). when the scl pin is released high, it is held that way for t brg . the data on the sda pin must remain stable for that duration and some hold time after the next falling edge of scl. after the eighth bit is shifted out (the falling edge of the eighth clock), the bf bit is cleared and the master releases sda, allowing the slave device being addressed to respond with an ack bit during the ninth bit time, if an address match occurs, or if data was received properly. the status of ack is written into the ackdt bit on the fall- ing edge of the ninth clock. if the master receives an acknowledge, the acknowledge status bit, ackstat, is cleared. if not, the bit is set. after the ninth clock, the sspif bit is set and the master clock (baud rate gen- erator) is suspended until the next data byte is loaded into the sspbuf, leaving scl low and sda unchanged (figure 13-15). after the write to the sspbuf, each bit of the address will be shifted out on the falling edge of scl, until all seven address bits and the r/w bit, are completed. on the falling edge of the eighth clock, the master will de-assert the sda pin, allowing the slave to respond with an acknowledge. on the falling edge of the ninth clock, the master will sample the sda pin to see if the address was recognized by a slave. the status of the ack bit is loaded into the ackstat status bit (sspcon2 register). following the falling edge of the ninth clock transmission of the address, the sspif is set, the bf bit is cleared and the baud rate generator is turned off, until another write to the sspbuf takes place, holding scl low and allowing sda to float. 13.4.8.1 bf status flag in transmit mode, the bf bit (sspstat register) is set when the cpu writes to sspbuf, and is cleared when all eight bits are shifted out. 13.4.8.2 wcol status flag if the user writes the sspbuf when a transmit is already in progress (i.e., sspsr is still shifting out a data byte), the wcol is set and the contents of the buffer are unchanged (the write doesn?t occur). wcol must be cleared in software. 13.4.8.3 ackstat status flag in transmit mode, the ackstat bit (sspcon2 register) is cleared when the slave has sent an acknowledge (ack = 0 ), and is set when the slave does not acknowledge (ack = 1 ). a slave sends an acknowledge when it has recognized its address (including a general call), or when the slave has properly received its data. 13.4.9 i 2 c? master mode reception master mode reception is enabled by programming the receive enable bit, rcen (sspcon2 register). the baud rate generator begins counting, and on each rollover, the state of the scl pin changes (high-to-low/low-to-high) and data is shifted into the sspsr. after the falling edge of the eighth clock, the rcen bit is automatically cleared, the contents of the sspsr are loaded into the sspbuf, the bf bit is set, the sspif flag bit is set and the baud rate generator is suspended from counting, holding scl low. the mssp is now in idle state, awaiting the next command. when the buffer is read by the cpu, the bf bit is auto- matically cleared. the user can then send an acknowl- edge bit at the end of reception, by setting the acknowledge sequence enable bit acken (sspcon2 register). 13.4.9.1 bf status flag in receive operation, the bf bit is set when an address or data byte is loaded into sspbuf from sspsr. it is cleared when the sspbuf register is read. 13.4.9.2 sspov status flag in receive operation, the sspov bit is set when eight bits are received into the sspsr and the bf bit is already set from a previous reception. 13.4.9.3 wcol status flag if the user writes the sspbuf when a receive is already in progress (i.e., sspsr is still shifting in a data byte), the wcol bit is set and the contents of the buffer are unchanged (the write doesn?t occur). note: the mssp module must be in an idle state before the rcen bit is set, or the rcen bit will be disregarded.
? 2007 microchip technology inc. preliminary ds41291d-page 195 pic16f882/883/884/886/887 figure 13-15: i 2 c? master mode waveform (transmission, 7 or 10-bit address) sda scl sspif bf sen a7 a6 a5 a4 a3 a2 a1 ack = 0 d7 d6 d5 d4 d3 d2 d1 d0 ack transmitting data or second half r/w = 0 transmit address to slave 123456789 123456789 p cleared in software service routine sspbuf is written in software from ssp interrupt after start condition, sen cleared by hardware. s sspbuf written with 7-bit address and r/w start transmit scl held low while cpu responds to sspif sen = 0 of 10-bit address write sspcon2<0> sen = 1 start condition begins from slave, clear ackstat bit sspcon2<6> ackstat in sspcon2 = 1 cleared in software sspbuf written pen cleared in software r/w
pic16f882/883/884/886/887 ds41291d-page 196 preliminary ? 2007 microchip technology inc. figure 13-16: i 2 c? master mode waveform (reception, 7-bit address) p 9 8 7 6 5 d0 d1 d2 d3 d4 d5 d6 d7 s a7 a6 a5 a4 a3 a2 a1 sda scl 12 3 4 5 6 7 8 9 12 3 4 5 678 9 1234 bus master terminates transfer ack receiving data from slave receiving data from slave d0 d1 d2 d3 d4 d5 d6 d7 ack r/w = 1 transmit address to slave sspif bf ack is not sent write to sspcon2<0> (sen = 1 ) write to sspbuf occurs here ack from slave master configured as a receiver by programming sspcon2<3>, (rcen = 1 ) pen bit = 1 written here data shifted in on falling edge of clk cleared in software start xmit sen = 0 sspov sda = 0 , scl = 1 while cpu ack last bit is shifted into sspsr and contents are unloaded into sspbuf cleared in software cleared in software set sspif interrupt at end of receive set p bit (sspstat<4>) and sspif cleared in software ack from master set sspif at end set sspif interrupt at end of acknowledge sequence set sspif interrupt at end of acknow- ledge sequence of receive set acken start acknowledge sequence sspov is set because sspbuf is still full sda = ackdt = 1 rcen cleared automatically rcen = 1 start next receive write to sspcon2<4> to start acknowledge sequence sda = ackdt (sspcon2<5>) = 0 rcen cleared automatically responds to sspif acken begin start condition cleared in software sda = ackdt = 0
? 2007 microchip technology inc. preliminary ds41291d-page 197 pic16f882/883/884/886/887 13.4.10 acknowledge sequence timing an acknowledge sequence is enabled by setting the acknowledge sequence enable bit, acken (sspcon2 register). when this bit is set, the scl pin is pulled low and the contents of the acknowledge data bit (ackdt) is presented on the sda pin. if the user wishes to gener- ate an acknowledge, then the ackdt bit should be cleared. if not, the user should set the ackdt bit before starting an acknowledge sequence. the baud rate generator then counts for one rollover period (t brg ) and the scl pin is de-asserted (pulled high). when the scl pin is sampled high (clock arbitration), the baud rate generator counts for t brg . the scl pin is then pulled low. following this, the acken bit is automatically cleared, the baud rate generator is turned off and the mssp module then goes into idle mode (figure 13-17). 13.4.10.1 wcol status flag if the user writes the sspbuf when an acknowledge sequence is in progress, then wcol is set and the contents of the buffer are unchanged (the write doesn?t occur). 13.4.11 stop condition timing a stop bit is asserted on the sda pin at the end of a receive/transmit by setting the stop sequence enable bit, pen (sspcon2 register). at the end of a receive/transmit, the scl line is held low after the fall- ing edge of the ninth clock. when the pen bit is set, the master will assert the sda line low. when the sda line is sampled low, the baud rate generator is reloaded and counts down to 0. when the baud rate generator times out, the scl pin will be brought high, and one t brg (baud rate generator rollover count) later, the sda pin will be de-asserted. when the sda pin is sam- pled high while scl is high, the p bit (sspstat regis- ter) is set. a t brg later, the pen bit is cleared and the sspif bit is set (figure 13-18). 13.4.11.1 wcol status flag if the user writes the sspbuf when a stop sequence is in progress, then the wcol bit is set and the contents of the buffer are unchanged (the write doesn?t occur). figure 13-17: acknowledge sequence waveform note: t brg = one baud rate generator period. sda scl set sspif at the end acknowledge sequence starts here, write to sspcon2 acken automatically cleared cleared in t brg t brg of receive ack 8 acken = 1 , ackdt = 0 d0 9 sspif software set sspif at the end of acknowledge sequence cleared in software
pic16f882/883/884/886/887 ds41291d-page 198 preliminary ? 2007 microchip technology inc. figure 13-18: stop cond ition receive or transmit mode 13.4.12 clock arbitration clock arbitration occurs when the master, during any receive, transmit or repeated start/stop condition, de-asserts the scl pin (scl allowed to float high). when the scl pin is allowed to float high, the baud rate generator (brg) is suspended from counting until the scl pin is actually sampled high. when the scl pin is sampled high, the baud rate generator is reloaded with the contents of sspadd<6:0> and begins counting. this ensures that the scl high time will always be at least one brg rollover count, in the event that the clock is held low by an external device (figure 13-19). 13.4.13 sleep operation while in sleep mode, the i 2 c module can receive addresses or data, and when an address match or complete byte transfer occurs, wake the processor from sleep (if the mssp interrupt is enabled). 13.4.14 effect of a reset a reset disables the mssp module and terminates the current transfer. figure 13-19: clock arbitrat ion timing in master transmit mode scl sda sda asserted low before rising edge of clock write to sspcon2 set pen falling edge of scl = 1 for t brg , followed by sda = 1 for t brg 9th clock scl brought high after t brg note: t brg = one baud rate generator period. t brg t brg after sda sampled high, p bit (sspstat) is set t brg to set up stop condition ack p t brg pen bit (sspcon2) is cleared by hardware and the sspif bit is set scl sda brg overflow, release scl, if scl = 1 , load brg with sspadd<6:0>, and start count brg overflow occurs, release scl, slave device holds scl low scl = 1 , brg starts counting clock high interval scl line sampled once every machine cycle (t osc *4), hold off brg until scl is sampled high t brg t brg t brg to measure high time interval
? 2007 microchip technology inc. preliminary ds41291d-page 199 pic16f882/883/884/886/887 13.4.15 multi-master mode in multi-master mode, the interrupt generation on the detection of the start and stop conditions allows the determination of when the bus is free. the stop (p) and start (s) bits are cleared from a reset, or when the mssp module is disabled. control of the i 2 c bus may be taken when the p bit (sspstat register) is set, or the bus is idle with both the s and p bits clear. when the bus is busy, enabling the ssp interrupt will gener- ate the interrupt when the stop condition occurs. in multi-master operation, the sda line must be moni- tored for arbitration, to see if the signal level is the expected output level. this check is performed in hard- ware, with the result placed in the bclif bit. arbitration can be lost in the following states: ? address transfer ? data transfer ? a start condition ? a repeated start condition ? an acknowledge condition 13.4.16 multi -master communication, bus collision, and bus arbitration multi-master mode support is achieved by bus arbitra- tion. when the master outputs address/data bits onto the sda pin, arbitration takes place when the master outputs a ? 1 ? on sda, by letting sda float high and another master asserts a ? 0 ?. when the scl pin floats high, data should be stable. if the expected data on sda is a ? 1 ? and the data sampled on the sda pin = 0 , then a bus collision has taken place. the master will set the bus collision interrupt flag (bclif) and reset the i 2 c port to its idle state (figure 13-20). if a transmit was in progress when the bus collision occurred, the transmission is halted, the bf bit is cleared, the sda and scl lines are de-asserted, and the sspbuf can be written to. when the user services the bus collision interrupt service routine, and if the i 2 c bus is free, the user can resume communication by asserting a start condition. if a start, repeated start, stop, or acknowledge condition was in progress when the bus collision occurred, the condition is aborted, the sda and scl lines are de-asserted, and the respective control bits in the sspcon2 register are cleared. when the user services the bus collision interrupt service routine, and if the i 2 c bus is free, the user can resume communication by asserting a start condition. the master will continue to monitor the sda and scl pins. if a stop condition occurs, the sspif bit will be set. a write to the sspbuf will start the transmission of data at the first data bit, regardless of where the trans- mitter left off when the bus collision occurred. in multi-master mode, the interrupt generation on the detection of start and stop conditions allows the determination of when the bus is free. control of the i 2 c bus can be taken when the p bit is set in the sspstat register, or the bus is idle and the s and p bits are cleared. figure 13-20: bus collision timing for transmit and acknowledge sda scl bclif sda released sda line pulled low by another source sample sda, while scl is high, data doesn?t bus collision has occurred set bus collision interrupt (bclif) match what is driven by the master, by master data changes while scl = 0
pic16f882/883/884/886/887 ds41291d-page 200 preliminary ? 2007 microchip technology inc. 13.4.16.1 bus collision during a start condition during a start condition, a bus collision occurs if: a) sda or scl are sampled low at the beginning of the start condition (figure 13-21). b) scl is sampled low before sda is asserted low (figure 13-22). during a start condition, both the sda and the scl pins are monitored, if: the sda pin is already low, or the scl pin is already low, then: the start condition is aborted, and the bclif flag is set, and the mssp module is reset to its idle state (figure 13-21). the start condition begins with the sda and scl pins de-asserted. when the sda pin is sampled high, the baud rate generator is loaded from sspadd<6:0> and counts down to 0. if the scl pin is sampled low while sda is high, a bus collision occurs, because it is assumed that another master is attempting to drive a data ? 1 ? during the start condition. if the sda pin is sampled low during this count, the brg is reset and the sda line is asserted early (figure 13-23). if, however, a ? 1 ? is sampled on the sda pin, the sda pin is asserted low at the end of the brg count. the baud rate generator is then reloaded and counts down to 0, and during this time, if the scl pin is sampled as ? 0 ?, a bus collision does not occur. at the end of the brg count, the scl pin is asserted low. figure 13-21: bus collision during start condition (sda only) note: the reason that bus collision is not a factor during a start condition, is that no two bus masters can assert a start condition at the exact same time. therefore, one master will always assert sda before the other. this condition does not cause a bus colli- sion, because the two masters must be allowed to arbitrate the first address follow- ing the start condition. if the address is the same, arbitration must be allowed to con- tinue into the data portion, repeated start or stop conditions. sda scl sen sda sampled low before sda goes low before the sen bit is set. s bit and sspif set because ssp module reset into idle state. sen cleared automatically because of bus collision. s bit and sspif set because set sen, enable start condition if sda = 1 , scl = 1 . sda = 0 , scl = 1 . bclif s sspif sda = 0 , scl = 1 . sspif and bclif are cleared in software. sspif and bclif are cleared in software. set bclif, start condition. set bclif.
? 2007 microchip technology inc. preliminary ds41291d-page 201 pic16f882/883/884/886/887 figure 13-22: bus collision d uring start condition (scl = 0 ) figure 13-23: brg reset due to sda arbitrat ion during start condition sda scl sen bus collision occurs, set bclif scl = 0 before sda = 0 , set sen, enable start sequence if sda = 1 , scl = 1 t brg t brg sda = 0 , scl = 1 bclif s sspif interrupt cleared in software bus collision occurs, set bclif scl = 0 before brg time-out, ? 0 ?? 0 ? ? 0 ? ? 0 ? sda scl sen set s set sen, enable start sequence if sda = 1 , scl = 1 less than t brg t brg sda = 0 , scl = 1 bclif s sspif s interrupts cleared in software set sspif sda = 0 , scl = 1 sda pulled low by other master reset brg and assert sda scl pulled low after brg time-out set sspif ? 0 ?
pic16f882/883/884/886/887 ds41291d-page 202 preliminary ? 2007 microchip technology inc. 13.4.16.2 bus collision during a repeated start condition during a repeated start condition, a bus collision occurs if: a) a low level is sampled on sda when scl goes from low level to high level. b) scl goes low before sda is asserted low, indi- cating that another master is attempting to trans- mit a data ? 1 ?. when the user de-asserts sda and the pin is allowed to float high, the brg is loaded with sspadd<6:0> and counts down to 0. the scl pin is then de-asserted, and when sampled high, the sda pin is sampled. if sda is low, a bus collision has occurred (i.e, another master is attempting to transmit a data ? 0 ?, see figure 13-24). if sda is sampled high, the brg is reloaded and begins counting. if sda goes from high-to-low before the brg times out, no bus collision occurs because no two masters can assert sda at exactly the same time. if scl goes from high-to-low before the brg times out and sda has not already been asserted, a bus collision occurs. in this case, another master is attempting to transmit a data ? 1 ? during the repeated start condition (figure 13-25). if at the end of the brg time-out, both scl and sda are still high, the sda pin is driven low and the brg is reloaded and begins counting. at the end of the count, regardless of the status of the scl pin, the scl pin is driven low and the repeated start condition is complete. figure 13-24: bus collision during a repeat ed start condition (case 1) figure 13-25: bus collision during repeat ed start condition (case 2) sda scl rsen bclif s sspif sample sda when scl goes high, if sda = 0 , set bclif and release sda and scl cleared in software ? 0 ? ? 0 ? sda scl bclif rsen s sspif interrupt cleared in software scl goes low before sda, set bclif, release sda and scl t brg t brg ? 0 ?
? 2007 microchip technology inc. preliminary ds41291d-page 203 pic16f882/883/884/886/887 13.4.16.3 bus collision during a stop condition bus collision occurs during a stop condition if: a) after the sda pin has been de-asserted and allowed to float high, sda is sampled low after the brg has timed out. b) after the scl pin is de-asserted, scl is sampled low before sda goes high. the stop condition begins with sda asserted low. when sda is sampled low, the scl pin is allowed to float. when the pin is sampled high (clock arbitration), the baud rate generator is loaded with sspadd<6:0> and counts down to 0. after the brg times out, sda is sampled. if sda is sampled low, a bus collision has occurred. this is due to another master attempting to drive a data ? 0 ? (figure 13-26). if the scl pin is sam- pled low before sda is allowed to float high, a bus col- lision occurs. this is another case of another master attempting to drive a data ? 0 ? (figure 13-27). figure 13-26: bus collision during a stop condition (case 1) figure 13-27: bus collision during a stop condition (case 2) sda scl bclif pen p sspif t brg t brg t brg sda asserted low sda sampled low after t brg , set bclif ? 0 ? ? 0 ? sda scl bclif pen p sspif t brg t brg t brg assert sda scl goes low before sda goes high, set bclif ? 0 ? ? 0 ?
pic16f882/883/884/886/887 ds41291d-page 204 preliminary ? 2007 microchip technology inc. 13.4.17 ssp mask register an ssp mask (sspmsk) register is available in i 2 c slave mode as a mask for the value held in the sspsr register during an address comparison operation. a zero (? 0 ?) bit in the sspmsk register has the effect of making the corresponding bit in the sspsr register a ?don?t care?. this register is reset to all ? 1 ?s upon any reset condition and, therefore, has no effect on standard ssp operation until written with a mask value. this register must be initiated prior to setting sspm<3:0> bits to select the i 2 c slave mode (7-bit or 10-bit address). this register can only be accessed when the appropriate mode is selected by bits (sspm<3:0> of sspcon). the ssp mask register is active during: ? 7-bit address mode: address compare of a<7:1>. ? 10-bit address mode: address compare of a<7:0> only. the ssp mask has no effect during the reception of the first (high) byte of the address. register 13-4: sspmsk: ssp mask register (1) r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 msk7 msk6 msk5 msk4 msk3 msk2 msk1 msk0 (2) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-1 msk<7:1>: mask bits 1 = the received address bit n is compared to sspadd to detect i 2 c address match 0 = the received address bit n is not used to detect i 2 c address match bit 0 msk<0>: mask bit for i 2 c slave mode, 10-bit address (2) i 2 c slave mode, 10-bit address (sspm<3:0> = 0111 ): 1 = the received address bit 0 is compared to sspadd<0> to detect i 2 c address match 0 = the received address bit 0 is not used to detect i 2 c address match note 1: when sspcon bits sspm<3:0> = 1001 , any reads or writes to the sspadd sfr address are accessed through the sspmsk register. 2: in all other ssp modes, this bit has no effect.
? 2007 microchip technology inc. preliminary ds41291d-page 205 pic16f882/883/884/886/887 14.0 special features of the cpu the pic16f882/883/884/886/887 have a host of fea- tures intended to maximize system reliability, minimize cost through elimination of external components, pro- vide power-saving features and offer code protection. these features are: ? reset - power-on reset (por) - power-up timer (pwrt) - oscillator start-up timer (ost) - brown-out reset (bor) ? interrupts ? watchdog timer (wdt) ? oscillator selection ? sleep ? code protection ? id locations ? in-circuit serial programming? the pic16f882/883/884/886/887 have two timers that offer necessary delays on power-up. one is the oscillator start-up timer (ost), intended to keep the chip in reset until the crystal oscillator is stable. the other is the power-up timer (pwrt), which provides a fixed delay of 64 ms (nominal) on power-up only, designed to keep the part in reset while the power supply stabilizes. there is also circuitry to reset the device if a brown-out occurs, which can use the power- up timer to provide at least a 64 ms reset. with these three functions-on-chip, most applications need no external reset circuitry. the sleep mode is designed to offer a very low-current power-down mode. the user can wake-up from sleep through: ? external reset ? watchdog timer wake-up ? an interrupt several oscillator options are also made available to allow the part to fit the application. the intosc option saves system cost while the lp crystal option saves power. a set of configuration bits are used to select various options (see register 14-3).
pic16f882/883/884/886/887 ds41291d-page 206 preliminary ? 2007 microchip technology inc. 14.1 configuration bits the configuration bits can be programmed (read as ? 0 ?), or left unprogrammed (read as ? 1 ?) to select various device configurations as shown in register 14-1. these bits are mapped in program memory location 2007h. note: address 2007h is beyond the user program memory space. it belongs to the special configuration memory space (2000h- 3fffh), which can be accessed only during programming. see ? pic16f88x memory programming specification? (ds41287) for more information. register 14-1: conf ig1: configuration word register 1 ? ?debug lvp fcmen ieso boren1 boren0 bit 15 bit 8 cpd cp mclre pwrte wdte fosc2 fosc1 fosc0 bit 7 bit 0 bit 15-14 unimplemented : read as ? 1 ? bit 13 debug : in-circuit debugger mode bit 1 = in-circuit debugger disabled, rb6/icspclk and rb7/icspdat are general purpose i/o pins 0 = in-circuit debugger enabled, rb6/icspclk and rb7/icspdat are dedicated to the debugger bit 12 lvp: low voltage programming enable bit 1 = rb3/pgm pin has pgm function, low voltage programming enabled 0 = rb3 pin is digital i/o, hv on mclr must be used for programming bit 11 fcmen: fail-safe clock monitor enabled bit 1 = fail-safe clock monitor is enabled 0 = fail-safe clock monitor is disabled bit 10 ieso: internal external switchover bit 1 = internal/external switchover mode is enabled 0 = internal/external switchover mode is disabled bit 9-8 boren<1:0>: brown-out reset selection bits (1) 11 = bor enabled 10 = bor enabled during operation and disabled in sleep 01 = bor controlled by sboren bit of the pcon register 00 = bor disabled bit 7 cpd : data code protection bit (2) 1 = data memory code protection is disabled 0 = data memory code protection is enabled bit 6 cp : code protection bit (3) 1 = program memory code protection is disabled 0 = program memory code protection is enabled bit 5 mclre: re3/mclr pin function select bit (4) 1 = re3/mclr pin function is mclr 0 = re3/mclr pin function is digital input, mclr internally tied to v dd bit 4 pwrte : power-up timer enable bit 1 = pwrt disabled 0 = pwrt enabled bit 3 wdte: watchdog timer enable bit 1 = wdt enabled 0 = wdt disabled and can be enabled by swdten bit of the wdtcon register bit 2-0 fosc<2:0>: oscillator selection bits 111 = rc oscillator: clkout function on ra6/osc2/clkout pin, rc on ra7/osc1/clkin 110 = rcio oscillator: i/o function on ra6/osc2/clkout pin, rc on ra7/osc1/clkin 101 = intosc oscillator: clkout function on ra6/osc2/clkout pin, i/o function on ra7/osc1/clkin 100 = intoscio oscillator: i/o function on ra6/osc2/clkout pin, i/o function on ra7/osc1/clkin 011 = ec: i/o function on ra6/osc2/clkout pin, clkin on ra7/osc1/clkin 010 = hs oscillator: high-speed crystal/resonator on ra6/osc2/clkout and ra7/osc1/clkin 001 = xt oscillator: crystal/resonator on ra6/osc2/clkout and ra7/osc1/clkin 000 = lp oscillator: low-power crystal on ra6/osc2/clkout and ra7/osc1/clkin note 1: enabling brown-out reset does not automatically enable power-up timer. 2: the entire data eeprom will be erased when the code protection is turned off. 3: the entire program memory will be erased when the code protection is turned off. 4: when mclr is asserted in intosc or rc mode, the internal clock oscillator is disabled.
? 2007 microchip technology inc. preliminary ds41291d-page 207 pic16f882/883/884/886/887 register 14-2: conf ig2: configuration word register 2 ? ? ? ? ? wrt1 wrt0 bor4v bit 15 bit 8 ? ? ? ? ? ? ? ? bit 7 bit 0 bit 15-11 unimplemented : read as ? 1 ? bit 10-9 wrt<1:0>: flash program memory self write enable bits pic16f883 / pic16f884 00 = 0000h to 07ffh write protected, 0800h to 0fffh may be modified by eecon control 01 = 0000h to 03ffh write protected, 0400h to 0fffh may be modified by eecon control 10 = 0000h to 00ffh write protected, 0100h to 0fffh may be modified by eecon control 11 = write protection off pic16f886 / pic16f887 00 = 0000h to 0fffh write protected, 1000h to 1fffh may be modified by eecon control 01 = 0000h to 07ffh write protected, 0800h to 1fffh may be modified by eecon control 10 = 0000h to 00ffh write protected, 0100h to 1fffh may be modified by eecon control 11 = write protection off pic16f882 00 = 0000h to 03ffh write protected, 0400h to 07ffh may be modified by eecon control 01 = 0000h to 00ffh write protected, 0100h to 07ffh may be modified by eecon control 11 = write protection off bit 8 bor4v : brown-out reset selection bit 0 = brown-out reset set to 2.1v 1 = brown-out reset set to 4.0v bit 7-0 unimplemented : read as ? 1 ?
pic16f882/883/884/886/887 ds41291d-page 208 preliminary ? 2007 microchip technology inc. 14.2 reset the pic16f882/883/884/886/887 differentiates between various kinds of reset: a) power-on reset (por) b) wdt reset during normal operation c) wdt reset during sleep d) mclr reset during normal operation e) mclr reset during sleep f) brown-out reset (bor) some registers are not affected in any reset condition; their status is unknown on por and unchanged in any other reset. most other registers are reset to a ?reset state? on: ? power-on reset ?mclr reset ?mclr reset during sleep ?wdt reset ? brown-out reset (bor) they are not affected by a wdt wake-up since this is viewed as the resumption of normal operation. to and pd bits are set or cleared differently in different reset situations, as indicated in table 14-2. these bits are used in software to determine the nature of the reset. see table 14-5 for a full description of reset states of all registers. a simplified block diagram of the on-chip reset circuit is shown in figure 14-1. the mclr reset path has a noise filter to detect and ignore small pulses. see section 17.0 ?electrical specifications? for pulse-width specifications. figure 14-1: simplified block diagram of on-chip reset circuit s rq external reset mclr /v pp pin v dd osc1/ wdt module v dd rise detect ost/pwrt lfintosc wdt time-out power-on reset ost 10-bit ripple counter pwrt chip_reset 11-bit ripple counter reset enable ost enable pwrt sleep brown-out (1) reset sboren boren clki pin note 1: refer to the configuration word register 1 (register 14-1).
? 2007 microchip technology inc. preliminary ds41291d-page 209 pic16f882/883/884/886/887 14.2.1 power-on reset (por) the on-chip por circuit holds the chip in reset until v dd has reached a high enough level for proper operation. a maximum rise time for v dd is required. see section 17.0 ?electrical specifications? for details. if the bor is enabled, the maximum rise time specification does not apply. the bor circuitry will keep the device in reset until v dd reaches v bor (see section 14.2.4 ?brown-out reset (bor)? ). when the device starts normal operation (exits the reset condition), device operating parameters (i.e., voltage, frequency, temperature, etc.) must be met to ensure operation. if these conditions are not met, the device must be held in reset until the operating conditions are met. for additional information, refer to application note an607, ?power-up trouble shooting? (ds00607). 14.2.2 mclr pic16f882/883/884/886/887 has a noise filter in the mclr reset path. the filter will detect and ignore small pulses. it should be noted that a wdt reset does not drive mclr pin low. the behavior of the esd protection on the mclr pin has been altered from early devices of this family. voltages applied to the pin that exceed its specification can result in both mclr resets and excessive current beyond the device specification during the esd event. for this reason, microchip recommends that the mclr pin no longer be tied directly to v dd . the use of an rc network, as shown in figure 14-2, is suggested. an internal mclr option is enabled by clearing the mclre bit in the configuration word register 1. when mclre = 0 , the reset signal to the chip is generated internally. when the mclre = 1 , the ra3/mclr pin becomes an external reset input. in this mode, the ra3/mclr pin has a weak pull-up to v dd . figure 14-2: recommended mclr circuit 14.2.3 power-up timer (pwrt) the power-up timer provides a fixed 64 ms (nominal) time-out on power-up only, from por or brown-out reset. the power-up timer operates from the 31 khz lfintosc oscillator. for more information, see section 4.5 ?internal clock modes? . the chip is kept in reset as long as pwrt is active. the pwrt delay allows the v dd to rise to an acceptable level. a configuration bit, pwrte, can disable (if set) or enable (if cleared or programmed) the power-up timer. the power-up timer should be enabled when brown-out reset is enabled, although it is not required. the power-up timer delay will vary from chip-to-chip and vary due to: ?v dd variation ? temperature variation ? process variation see dc parameters for details ( section 17.0 ?electrical specifications? ). note: the por circuit does not produce an internal reset when v dd declines. to re-enable the por, v dd must reach vss for a minimum of 100 s. v dd pic16f886 mclr r1 1k ( or greater) c1 0.1 f (optional, not critical)
pic16f882/883/884/886/887 ds41291d-page 210 preliminary ? 2007 microchip technology inc. 14.2.4 brown-out reset (bor) the boren0 and boren1 bits in the configuration word register 1 select one of four bor modes. two modes have been added to allow software or hardware control of the bor enable. when boren<1:0> = 01 , the sboren bit (pcon<4>) enables/disables the bor allowing it to be controlled in software. by selecting boren<1:0>, the bor is automatically disabled in sleep to conserve power and enabled on wake-up. in this mode, the sboren bit is disabled. see register 14-3 for the configuration word definition. the bor4v bit in the configuration word register 2 selects one of two brown-out reset voltages. when bor4b = 1 , v bor is set to 4v. when bor4v = 0 , v bor is set to 2.1v. if v dd falls below v bor for greater than parameter (t bor ) (see section 17.0 ?electrical specifications? ), the brown-out situation will reset the device. this will occur regardless of v dd slew rate. a reset is not insured to occur if v dd falls below v bor for less than parameter (t bor ). on any reset (power-on, brown-out reset, watchdog timer, etc.), the chip will remain in reset until v dd rises above v bor (see figure 14-3). the power-up timer will now be invoked, if enabled and will keep the chip in reset an additional 64 ms. if v dd drops below v bor while the power-up timer is running, the chip will go back into a brown-out reset and the power-up timer will be re-initialized. once v dd rises above v bor , the power-up timer will execute a 64 ms reset. figure 14-3: brown-out situations note: the power-up timer is enabled by the pwrte bit in the configuration word register 1. 64 ms (1) v bor v dd internal reset v bor v dd internal reset 64 ms (1) < 64 ms 64 ms (1) v bor v dd internal reset note 1: 64 ms delay only if pwrte bit is programmed to ? 0 ?.
? 2007 microchip technology inc. preliminary ds41291d-page 211 pic16f882/883/884/886/887 14.2.5 time-out sequence on power-up, the time-out sequence is as follows: first, pwrt time-out is invoked after por has expired, then ost is activated after the pwrt time-out has expired. the total time-out will vary based on oscillator configuration and pwrte bit status. for example, in ec mode with pwrte bit erased (pwrt disabled), there will be no time-out at all. figures 14-4, 14-5 and 14-6 depict time-out sequences. the device can execute code from the intosc while ost is active by enabling two-speed start-up or fail-safe monitor (see section 4.7.2 ?two-speed start-up sequence? and section 4.8 ?fail-safe clock monitor? ). since the time-outs occur from the por pulse, if mclr is kept low long enough, the time-outs will expire. then, bringing mclr high will begin execution immediately (see figure 14-5). this is useful for testing purposes or to synchronize more than one pic16f882/883/884/ 886/887 device operating in parallel. table 14-5 shows the reset conditions for some special registers, while table 14-4 shows the reset conditions for all the registers. 14.2.6 power control (pcon) register the power control register pcon (address 8eh) has two status bits to indicate what type of reset that last occurred. bit 0 is bor (brown-out reset). bor is unknown on power-on reset. it must then be set by the user and checked on subsequent resets to see if bor = 0 , indicating that a brown-out has occurred. the bor status bit is a ?don?t care? and is not necessarily predictable if the brown-out circuit is disabled (boren<1:0> = 00 in the configuration word register 1). bit 1 is por (power-on reset). it is a ? 0 ? on power-on reset and unaffected otherwise. the user must write a ? 1 ? to this bit following a power-on reset. on a subsequent reset, if por is ? 0 ?, it will indicate that a power-on reset has occurred (i.e., v dd may have gone too low). for more information, see section 3.2.2 ?ultra low- power wake-up? and section 14.2.4 ?brown-out reset (bor)? . table 14-1: time-out in various situations table 14-2: status/pcon bits and their significance table 14-3: summary of registers associated with brown-out oscillator configuration power-up brown-out reset wake-up from sleep pwrte = 0 pwrte = 1 pwrte = 0 pwrte = 1 xt, hs, lp t pwrt + 1024 ? t osc 1024 ? t osc t pwrt + 1024 ? t osc 1024 ? t osc 1024 ? t osc lp, t1oscin = 1 t pwrt ?t pwrt ?? rc, ec, intosc t pwrt ?t pwrt ?? por bor to pd condition 0x11 power-on reset u011 brown-out reset uu0u wdt reset uu00 wdt wake-up uuuu mclr reset during normal operation uu10 mclr reset during sleep legend: u = unchanged, x = unknown name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets pcon ? ? ulpwue sboren ? ?por bor --01 --qq --0u --uu status irp rp1 rpo to pd z dc c 0001 1xxx 000q quuu legend: u = unchanged, x = unknown, ? = unimplemented bit, reads as ? 0 ?, q = value depends on condition. shaded cells are not used by bor. note 1: other (non power-up) resets include mclr reset and watchdog timer reset during normal operation.
pic16f882/883/884/886/887 ds41291d-page 212 preliminary ? 2007 microchip technology inc. figure 14-4: time-out sequence on power-up (delayed mclr ): case 1 figure 14-5: time-out sequence on power-up (delayed mclr ): case 2 figure 14-6: time-out sequence on power-up (mclr with v dd ) t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset v dd mclr internal por pwrt time-out ost time-out internal reset t pwrt t ost t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset
? 2007 microchip technology inc. preliminary ds41291d-page 213 pic16f882/883/884/886/887 table 14-4: initialization condition for register register address power-on reset mclr reset wdt reset brown-out reset (1) wake-up from sleep through interrupt wake-up from sleep through wdt time-out w? xxxx xxxx uuuu uuuu uuuu uuuu indf 00h/80h/ 100h/180h xxxx xxxx xxxx xxxx uuuu uuuu tmr0 01h/101h xxxx xxxx uuuu uuuu uuuu uuuu pcl 02h/82h/ 102h/182h 0000 0000 0000 0000 pc + 1 (3) status 03h/83h/ 103h/183h 0001 1xxx 000q quuu (4) uuuq quuu (4) fsr 04h/84h/ 104h/184h xxxx xxxx uuuu uuuu uuuu uuuu porta 05h xxxx xxxx 0000 0000 uuuu uuuu portb 06h/106h xxxx xxxx 0000 0000 uuuu uuuu portc 07h xxxx xxxx 0000 0000 uuuu uuuu portd 08h xxxx xxxx 0000 0000 uuuu uuuu porte 09h ---- xxxx ---- 0000 ---- uuuu pclath 0ah/8ah/ 10ah/18ah ---0 0000 ---0 0000 ---u uuuu intcon 0bh/8bh/ 10bh/18bh 0000 000x 0000 000u uuuu uuuu (2) pir1 0ch 0000 0000 0000 0000 uuuu uuuu (2) pir2 0dh 0000 0000 0000 0000 uuuu uuuu (2) tmr1l 0eh xxxx xxxx uuuu uuuu uuuu uuuu tmr1h 0fh xxxx xxxx uuuu uuuu uuuu uuuu t1con 10h 0000 0000 uuuu uuuu -uuu uuuu tmr2 11h 0000 0000 0000 0000 uuuu uuuu t2con 12h -000 0000 -000 0000 -uuu uuuu sspbuf 13h xxxx xxxx uuuu uuuu uuuu uuuu sspcon 14h 0000 0000 0000 0000 uuuu uuuu ccpr1l 15h xxxx xxxx uuuu uuuu uuuu uuuu ccpr1h 16h xxxx xxxx uuuu uuuu uuuu uuuu ccp1con 17h 0000 0000 0000 0000 uuuu uuuu rcsta 18h 0000 000x 0000 0000 uuuu uuuu txreg 19h 0000 0000 0000 0000 uuuu uuuu rcreg 1ah 0000 0000 0000 0000 uuuu uuuu ccpr2l 1bh xxxx xxxx uuuu uuuu uuuu uuuu legend: u = unchanged, x = unknown, ? = unimplemented bit, reads as ? 0 ?, q = value depends on condition. note 1: if v dd goes too low, power-on reset will be activated and registers will be affected differently. 2: one or more bits in intcon and/or pir1 will be affected (to cause wake-up). 3: when the wake-up is due to an interrupt and the gie bit is set, the pc is loaded with the interrupt vector (0004h). 4: see table 14-5 for reset value for specific condition. 5: if reset was due to brown-out, then bit 0 = 0 . all other resets will cause bit 0 = u . 6: accessible only when sspcon register bits sspm<3:0> = 1001 .
pic16f882/883/884/886/887 ds41291d-page 214 preliminary ? 2007 microchip technology inc. ccpr2h 1ch xxxx xxxx uuuu uuuu uuuu uuuu ccp2con 1dh --00 0000 --00 0000 --uu uuuu adresh 1eh xxxx xxxx uuuu uuuu uuuu uuuu adcon0 1fh 00-0 0000 00-0 0000 uu-u uuuu option_reg 81h/181h 1111 1111 1111 1111 uuuu uuuu trisa 85h 1111 1111 1111 1111 uuuu uuuu trisb 86h/186h 1111 1111 1111 1111 uuuu uuuu trisc 87h 1111 1111 1111 1111 uuuu uuuu trisd 88h 1111 1111 1111 1111 uuuu uuuu trise 89h ---- 1111 ---- 1111 ---- uuuu pie1 8ch 0000 0000 0000 0000 uuuu uuuu pie2 8dh 0000 0000 0000 0000 uuuu uuuu pcon 8eh --01 --0x --0u --uu (1, 5) --uu --uu osccon 8fh -110 q000 -110 q000 -uuu uuuu osctune 90h ---0 0000 ---u uuuu ---u uuuu sspcon2 91h 0000 0000 0000 0000 uuuu uuuu pr2 92h 1111 1111 1111 1111 1111 1111 sspadd (6) 93h 0000 0000 0000 0000 uuuu uuuu sspmsk (6) 93h 1111 1111 1111 1111 1111 1111 sspstat 94h 0000 0000 0000 0000 uuuu uuuu wpub 95h 1111 1111 1111 1111 uuuu uuuu iocb 96h 0000 0000 0000 0000 uuuu uuuu vrcon 97h 0000 0000 0000 0000 uuuu uuuu txsta 98h 0000 -010 0000 -010 uuuu -uuu spbrg 99h 0000 0000 0000 0000 uuuu uuuu spbrgh 9ah 0000 0000 0000 0000 uuuu uuuu pwm1con 9bh 0000 0000 0000 0000 uuuu uuuu eccpas 9ch 0000 0000 0000 0000 uuuu uuuu pstrcon 9dh ---0 0001 ---0 0001 ---u uuuu adresl 9eh xxxx xxxx uuuu uuuu uuuu uuuu adcon1 9fh 0-00 ---- 0-00 ---- u-uu ---- wdtcon 105h ---0 1000 ---0 1000 ---u uuuu cm1con0 107h 0000 0-00 0000 0-00 uuuu u-uu cm2con0 108h 0000 0-00 0000 0-00 uuuu u-uu table 14-4: initialization condition for register (continued) register address power-on reset mclr reset wdt reset (continued) brown-out reset (1) wake-up from sleep through interrupt wake-up from sleep through wdt time-out (continued) legend: u = unchanged, x = unknown, ? = unimplemented bit, reads as ? 0 ?, q = value depends on condition. note 1: if v dd goes too low, power-on reset will be activated and registers will be affected differently. 2: one or more bits in intcon and/or pir1 will be affected (to cause wake-up). 3: when the wake-up is due to an interrupt and the gie bit is set, the pc is loaded with the interrupt vector (0004h). 4: see table 14-5 for reset value for specific condition. 5: if reset was due to brown-out, then bit 0 = 0 . all other resets will cause bit 0 = u . 6: accessible only when sspcon register bits sspm<3:0> = 1001 .
? 2007 microchip technology inc. preliminary ds41291d-page 215 pic16f882/883/884/886/887 table 14-5: initialization condition for special registers cm2con1 109h 0000 0--0 0000 0--0 uuuu u--u eedat 10ch 0000 0000 0000 0000 uuuu uuuu eeadr 10dh 0000 0000 0000 0000 uuuu uuuu eedath 10eh --00 0000 --00 0000 --uu uuuu eeadrh 10fh ---0 0000 ---0 0000 ---u uuuu srcon 185h 0000 00-0 0000 00-0 uuuu uu-u baudctl 187h 01-0 0-00 01-0 0-00 uu-u u-uu ansel 188h 1111 1111 1111 1111 uuuu uuuu anselh 189h 1111 1111 1111 1111 uuuu uuuu eecon1 18ch ---- x000 ---- q000 ---- uuuu eecon2 18dh ---- ---- ---- ---- ---- ---- condition program counter status register pcon register power-on reset 000h 0001 1xxx --01 --0x mclr reset during normal operation 000h 000u uuuu --0u --uu mclr reset during sleep 000h 0001 0uuu --0u --uu wdt reset 000h 0000 uuuu --0u --uu wdt wake-up pc + 1 uuu0 0uuu --uu --uu brown-out reset 000h 0001 1uuu --01 --u0 interrupt wake-up from sleep pc + 1 (1) uuu1 0uuu --uu --uu legend: u = unchanged, x = unknown, ? = unimplemented bit, reads as ? 0 ?. note 1: when the wake-up is due to an interrupt and global interrupt enable bit, gie, is set, the pc is loaded with the interrupt vector (0004h) after execution of pc + 1. table 14-4: initialization condition for register (continued) register address power-on reset mclr reset wdt reset (continued) brown-out reset (1) wake-up from sleep through interrupt wake-up from sleep through wdt time-out (continued) legend: u = unchanged, x = unknown, ? = unimplemented bit, reads as ? 0 ?, q = value depends on condition. note 1: if v dd goes too low, power-on reset will be activated and registers will be affected differently. 2: one or more bits in intcon and/or pir1 will be affected (to cause wake-up). 3: when the wake-up is due to an interrupt and the gie bit is set, the pc is loaded with the interrupt vector (0004h). 4: see table 14-5 for reset value for specific condition. 5: if reset was due to brown-out, then bit 0 = 0 . all other resets will cause bit 0 = u . 6: accessible only when sspcon register bits sspm<3:0> = 1001 .
pic16f882/883/884/886/887 ds41291d-page 216 preliminary ? 2007 microchip technology inc. 14.3 interrupts the pic16f882/883/884/886/887 has multiple inter- rupt sources: ? external interrupt rb0/int ? timer0 overflow interrupt ? portb change interrupts ? 2 comparator interrupts ? a/d interrupt ? timer1 overflow interrupt ? timer2 match interrupt ? eeprom data write interrupt ? fail-safe clock monitor interrupt ? enhanced ccp interrupt ? eusart receive and transmit interrupts ? ultra low-power wake-up interrupt ? mssp interrupt the interrupt control register (intcon) and peripheral interrupt request register 1 (pir1) record individual interrupt requests in flag bits. the intcon register also has individual and global interrupt enable bits. a global interrupt enable bit, gie (intcon<7>), enables (if set) all unmasked interrupts, or disables (if cleared) all interrupts. individual interrupts can be disabled through their corresponding enable bits in the intcon, pie1 and pie2 registers, respectively. gie is cleared on reset. the return from interrupt instruction, retfie , exits the interrupt routine, as well as sets the gie bit, which re-enables unmasked interrupts. the following interrupt flags are contained in the intcon register: ? int pin interrupt ? portb change interrupts ? timer0 overflow interrupt the peripheral interrupt flags are contained in the pir1 and pir2 registers. the corresponding interrupt enable bits are contained in pie1 and pie2 registers. the following interrupt flags are contained in the pir1 register: ? a/d interrupt ? eusart receive and transmit interrupts ? timer1 overflow interrupt ? synchronous serial port (ssp) interrupt ? enhanced ccp1 interrupt ? timer1 overflow interrupt ? timer2 match interrupt the following interrupt flags are contained in the pir2 register: ? fail-safe clock monitor interrupt ? 2 comparator interrupts ? eeprom data write interrupt ? ultra low-power wake-up interrupt ? ccp2 interrupt when an interrupt is serviced: ? the gie is cleared to disable any further interrupt. ? the return address is pushed onto the stack. ? the pc is loaded with 0004h. for external interrupt events, such as the int pin, portb change interrupts, the interrupt latency will be three or four instruction cycles. the exact latency depends upon when the interrupt event occurs (see figure 14-8). the latency is the same for one or two- cycle instructions. once in the interrupt service routine, the source(s) of the interrupt can be determined by polling the interrupt flag bits. the interrupt flag bit(s) must be cleared in software before re-enabling interrupts to avoid multiple interrupt requests. for additional information on timer1, timer2, comparators, a/d, data eeprom, eusart, mssp or enhanced ccp modules, refer to the respective peripheral section. 14.3.1 rb0/int interrupt external interrupt on rb0/int pin is edge-triggered; either rising if the intedg bit (option_reg<6>) is set, or falling, if the intedg bit is clear. when a valid edge appears on the rb0/int pin, the intf bit (intcon<1>) is set. this interrupt can be disabled by clearing the inte control bit (intcon<4>). the intf bit must be cleared in software in the interrupt service routine before re-enabling this interrupt. the rb0/int interrupt can wake-up the processor from sleep, if the inte bit was set prior to going into sleep. the status of the gie bit decides whether or not the processor branches to the interrupt vector following wake-up (0004h). see section 14.6 ?power-down mode (sleep)? for details on sleep and figure 14-10 for timing of wake-up from sleep through rb0/int interrupt. note 1: individual interrupt flag bits are set, regardless of the status of their corresponding mask bit or the gie bit. 2: when an instruction that clears the gie bit is executed, any interrupts that were pending for execution in the next cycle are ignored. the interrupts, which were ignored, are still pending to be serviced when the gie bit is set again.
? 2007 microchip technology inc. preliminary ds41291d-page 217 pic16f882/883/884/886/887 14.3.2 timer0 interrupt an overflow (ffh 00h) in the tmr0 register will set the t0if (intcon<2>) bit. the interrupt can be enabled/disabled by setting/clearing t0ie (intcon<5>) bit. see section 5.0 ?timer0 module? for operation of the timer0 module. 14.3.3 portb interrupt an input change on portb change sets the rbif (intcon<0>) bit. the interrupt can be enabled/ disabled by setting/clearing the rbie (intcon<3>) bit. plus, individual pins can be configured through the iocb register. figure 14-7: interrupt logic note: if a change on the i/o pin should occur when the read operation is being executed (start of the q2 cycle), then the rbif inter- rupt flag may not get set. see section 3.4.3 ?interrupt-on-change? for more information. c1if c1ie t0if t0ie intf inte rbif rbie gie peie wake-up (if in sleep mode) (1) interrupt to cpu eeie eeif adif adie ioc-rb0 iocb0 ioc-rb1 iocb1 ioc-rb2 iocb2 ioc-rb3 iocb3 ccp1if ccp1ie osfif osfie c2if c2ie ioc-rb4 iocb4 ioc-rb5 iocb5 ioc-rb6 iocb6 ioc-rb7 iocb7 rcif rcie tmr2ie tmr2if sspie sspif txie txif tmr1ie tmr1if note 1: some peripherals depend upon the system clock for operation. since the system clock is suspended during sleep, these peripherals will not wake the part from sleep. see section 14.6.1 ?wake-up from sleep? . bclie bclif ulpwuif ulpwuie ccp2if ccp2ie
pic16f882/883/884/886/887 ds41291d-page 218 preliminary ? 2007 microchip technology inc. figure 14-8: int pin interrupt timing table 14-6: summary of interrupt registers name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets intcon gie peie t0ie inte rbie t0if intf rbif 0000 000x 0000 000x pie1 ? adie rcie txie sspie ccp1ie tmr2ie tmr1ie -000 0000 -000 0000 pie2 osfie c2ie c1ie eeie bclie ulpwuie ? ccp2ie 0000 00-0 0000 00-0 pir1 ? adif rcif txif sspif ccp1if tmr2if tmr1if -000 0000 -000 0000 pir2 osfif c2if c1if eeif bclif ulpwuif ? ccp2if 0000 00-0 0000 00-0 legend: x = unknown, u = unchanged, ? = unimplemented read as ? 0 ?, q = value depends upon condition. shaded cells are not used by the interrupt module. q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 osc1 clkout int pin intf flag (intcon<1>) gie bit (intcon<7>) instruction flow pc instruction fetched instruction executed interrupt latency pc pc + 1 pc + 1 0004h 0005h inst (0004h) inst (0005h) dummy cycle inst (pc) inst (pc + 1) inst (pc ? 1) inst (0004h) dummy cycle inst (pc) ? note 1: intf flag is sampled here (every q1). 2: asynchronous interrupt latency = 3-4 t cy . synchronous latency = 3 t cy , where t cy = instruction cycle time. latency is the same whether inst (pc) is a single cycle or a 2-cycle instruction. 3: clkout is available only in intosc and rc oscillator modes. 4: for minimum width of int pulse, refer to ac specifications in section 17.0 ?electrical specifications? . 5: intf is enabled to be set any time during the q4-q1 cycles. (1) (2) (3) (4) (5) (1)
? 2007 microchip technology inc. preliminary ds41291d-page 219 pic16f882/883/884/886/887 14.4 context saving during interrupts during an interrupt, only the return pc value is saved on the stack. typically, users may wish to save key registers during an interrupt (e.g., w and status registers). this must be implemented in software. since the upper 16 bytes of all gpr banks are com- mon in the pic16f882/883/884/886/887 (see figures 2-2 and 2-3), temporary holding registers, w_temp and status_temp, should be placed in here. these 16 locations do not require banking and therefore, make it easier to context save and restore. the same code shown in example 14-1 can be used to: ? store the w register ? store the status register ? execute the isr code ? restore the status (and bank select bit register) ? restore the w register example 14-1: saving status and w registers in ram note: the pic16f882/883/884/886/887 nor- mally does not require saving the pclath. however, if computed goto ?s are used in the isr and the main code, the pclath must be saved and restored in the isr. movwf w_temp ;copy w to temp register swapf status,w ;swap status to be saved into w ;swaps are used because they do not affect the status bits movwf status_temp ;save status to bank zero status_temp register : :(isr) ;insert user code here : swapf status_temp,w ;swap status_temp register into w ;(sets bank to original state) movwf status ;move w into status register swapf w_temp,f ;swap w_temp swapf w_temp,w ;swap w_temp into w
pic16f882/883/884/886/887 ds41291d-page 220 preliminary ? 2007 microchip technology inc. 14.5 watchdog timer (wdt) the wdt has the following features: ? operates from the lfintosc (31 khz) ? contains a 16-bit prescaler ? shares an 8-bit prescaler with timer0 ? time-out period is from 1 ms to 268 seconds ? configuration bit and software controlled wdt is cleared under certain conditions described in table 14-7. 14.5.1 wdt oscillator the wdt derives its time base from the 31 khz lfintosc. the lts bit of the osccon register does not reflect that the lfintosc is enabled. the value of wdtcon is ? ---0 1000 ? on all resets. this gives a nominal time base of 17 ms. 14.5.2 wdt control the wdte bit is located in the configuration word register 1. when set, the wdt runs continuously. when the wdte bit in the configuration word register 1 is set, the swdten bit of the wdtcon register has no effect. if wdte is clear, then the swdten bit can be used to enable and disable the wdt. setting the bit will enable it and clearing the bit will disable it. the psa and ps<2:0> bits of the option register have the same function as in previous versions of the pic16f882/883/884/886/887 family of microcontrol- lers. see section 5.0 ?timer0 module? for more infor- mation. figure 14-9: watchdog timer block diagram note: when the oscillator start-up timer (ost) is invoked, the wdt is held in reset, because the wdt ripple counter is used by the ost to perform the oscillator delay count. when the ost count has expired, the wdt will begin counting (if enabled). table 14-7: wdt status conditions wdt wdte = 0 cleared clrwdt command oscillator fail detected exit sleep + system clock = t1osc, extrc, intosc, extclk exit sleep + system clock = xt, hs, lp cleared until the end of ost 31 khz psa 16-bit wdt prescaler from tmr0 clock source prescaler (1) 8 ps<2:0> psa wdt time-out to t m r 0 wdtps<3:0> wdte from the configuration word register 1 1 1 0 0 swdten from wdtcon lfintosc clock note 1: this is the shared timer0/wdt prescaler. see section 5.4 ?prescaler? for more information.
? 2007 microchip technology inc. preliminary ds41291d-page 221 pic16f882/883/884/886/887 table 14-8: summary of watchdog timer register register 14-3: wdtcon: watchdog timer control register u-0 u-0 u-0 r/w-0 r/w-1 r/w-0 r/w-0 r/w-0 ? ? ? wdtps3 wdtps2 wdtps1 wdtps0 swdten (1) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4-1 wdtps<3:0>: watchdog timer period select bits bit value = prescale rate 0000 = 1:32 0001 = 1:64 0010 = 1:128 0011 = 1:256 0100 = 1:512 (reset value) 0101 = 1:1024 0110 = 1:2048 0111 = 1:4096 1000 = 1:8192 1001 = 1:16384 1010 = 1:32768 1011 = 1:65536 1100 = reserved 1101 = reserved 1110 = reserved 1111 = reserved bit 0 swdten: software enable or disable the watchdog timer (1) 1 = wdt is turned on 0 = wdt is turned off (reset value) note 1: if wdte configuration bit = 1 , then wdt is always enabled, irrespective of this control bit. if wdte configuration bit = 0 , then it is possible to turn wdt on/off with this control bit. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor value on all other resets config1 (1) cpd cp mclre pwrte wdte fosc2 fosc1 fosc0 ?? option_reg rbpu intedg t0cs t0se psa ps2 ps1 ps0 1111 1111 1111 1111 wdtcon ? ? ? wdtps3 wdtps2 wstps1 wdtps0 swdten ---0 1000 ---0 1000 legend: shaded cells are not used by the watchdog timer. note 1: see register 14-1 for operation of all configuration word register 1 bits.
pic16f882/883/884/886/887 ds41291d-page 222 preliminary ? 2007 microchip technology inc. 14.6 power-down mode (sleep) the power-down mode is entered by executing a sleep instruction. if the watchdog timer is enabled: ? wdt will be cleared but keeps running. ?pd bit in the status register is cleared. ?to bit is set. ? oscillator driver is turned off. ? i/o ports maintain the status they had before sleep was executed (driving high, low or high- impedance). for lowest current consumption in this mode, all i/o pins should be either at v dd or v ss , with no external circuitry drawing current from the i/o pin and the comparators and cv ref should be disabled. i/o pins that are high- impedance inputs should be pulled high or low externally to avoid switching currents caused by floating inputs. the t0cki input should also be at v dd or v ss for lowest current consumption. the contribution from on-chip pull- ups on porta should be considered. the mclr pin must be at a logic high level. 14.6.1 wake-up from sleep the device can wake-up from sleep through one of the following events: 1. external reset input on mclr pin. 2. watchdog timer wake-up (if wdt was enabled). 3. interrupt from rb0/int pin, portb change or a peripheral interrupt. the first event will cause a device reset. the two latter events are considered a continuation of program exe- cution. the to and pd bits in the status register can be used to determine the cause of device reset. the pd bit, which is set on power-up, is cleared when sleep is invoked. to bit is cleared if wdt wake-up occurred. the following peripheral interrupts can wake the device from sleep: 1. tmr1 interrupt. timer1 must be operating as an asynchronous counter. 2. eccp capture mode interrupt. 3. a/d conversion (when a/d clock source is frc). 4. eeprom write operation completion. 5. comparator output changes state. 6. interrupt-on-change. 7. external interrupt from int pin. 8. eusart break detect, i 2 c slave. other peripherals cannot generate interrupts since during sleep, no on-chip clocks are present. when the sleep instruction is being executed, the next instruction (pc + 1) is prefetched. for the device to wake-up through an interrupt event, the corresponding interrupt enable bit must be set (enabled). wake-up occurs regardless of the state of the gie bit. if the gie bit is clear (disabled), the device continues execution at the instruction after the sleep instruction. if the gie bit is set (enabled), the device executes the instruction after the sleep instruction, then branches to the inter- rupt address (0004h). in cases where the execution of the instruction following sleep is not desirable, the user should have a nop after the sleep instruction. the wdt is cleared when the device wakes up from sleep, regardless of the source of wake-up. 14.6.2 wake-up using interrupts when global interrupts are disabled (gie cleared) and any interrupt source has both its interrupt enable bit and interrupt flag bit set, one of the following will occur: ? if the interrupt occurs before the execution of a sleep instruction, the sleep instruction will complete as a nop . therefore, the wdt and wdt prescaler and postscaler (if enabled) will not be cleared, the to bit will not be set and the pd bit will not be cleared. ? if the interrupt occurs during or after the execu- tion of a sleep instruction, the device will imme- diately wake-up from sleep. the sleep instruction will be completely executed before the wake-up. therefore, the wdt and wdt prescaler and postscaler (if enabled) will be cleared, the to bit will be set and the pd bit will be cleared. even if the flag bits were checked before executing a sleep instruction, it may be possible for flag bits to become set before the sleep instruction completes. to determine whether a sleep instruction executed, test the pd bit. if the pd bit is set, the sleep instruction was executed as a nop . to ensure that the wdt is cleared, a clrwdt instruction should be executed before a sleep instruction. note: it should be noted that a reset generated by a wdt time-out does not drive mclr pin low. note: if the global interrupts are disabled (gie is cleared), but any interrupt source has both its interrupt enable bit and the corresponding interrupt flag bits set, the device will immediately wake-up from sleep. the sleep instruction is completely executed.
? 2007 microchip technology inc. preliminary ds41291d-page 223 pic16f882/883/884/886/887 figure 14-10: wake-up from sleep through interrupt 14.7 code protection if the code protection bit(s) have not been programmed, the on-chip program memory can be read out using icsp ? for verification purposes. 14.8 id locations four memory locations (2000h-2003h) are designated as id locations where the user can store checksum or other code identification numbers. these locations are not accessible during normal execution but are readable and writable during program/verify mode. only the least significant 7 bits of the id locations are used. 14.9 in-circuit serial programming? the pic16f882/883/884/886/887 microcontrollers can be serially programmed while in the end application cir- cuit. this is simply done with two lines for clock and data and three other lines for: ? power ? ground ? programming voltage this allows customers to manufacture boards with unprogrammed devices and then program the micro- controller just before shipping the product. this also allows the most recent firmware or a custom firmware to be programmed. the device is placed into a program/verify mode by holding the rb6/icspclk and rb7/icspdat pins low, while raising the mclr (v pp ) pin from v il to v ihh . see the ? pic16f88x memory programming specification? (ds41287) for more information. rb7 becomes the programming data and rb0 becomes the programming clock. both rb7 and rb0 are schmitt trigger inputs in this mode. after reset, to place the device into program/verify mode, the program counter (pc) is at location 00h. a 6-bit command is then supplied to the device. depending on the command, 14 bits of program data are then supplied to or from the device, depending on whether the command was a load or a read. for complete details of serial programming, please refer to the ? pic16f88x memory programming specification? (ds41287). a typical in-circuit serial programming connection is shown in figure 14-11. q1 q2 q3 q4 q1 q2 q3 q4 q1 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 clkout (4) int pin intf flag (intcon<1>) gie bit (intcon<7>) instruction flow pc instruction fetched instruction executed pc pc + 1 pc + 2 inst(pc) = sleep inst(pc ? 1) inst(pc + 1) sleep processor in sleep interrupt latency (3) inst(pc + 2) inst(pc + 1) inst(0004h) inst(0005h) inst(0004h) dummy cycle pc + 2 0004h 0005h dummy cycle t ost (2) pc + 2 note 1: xt, hs or lp oscillator mode assumed. 2: t ost = 1024 t osc (drawing not to scale). this delay does not apply to ec and rc oscillator modes. 3: gie = 1 assumed. in this case after wake-up, the processor jumps to 0004h. if gie = 0 , execution will continue in-line. 4: clkout is not available in xt, hs, lp or ec oscillator modes, but shown here for timing reference. note: the entire data eeprom and flash program memory will be erased when the code protection is switched from on to off. see the ? pic16f88x memory programming specification? (ds41287) for more information.
pic16f882/883/884/886/887 ds41291d-page 224 preliminary ? 2007 microchip technology inc. figure 14-11: typical in-circuit serial programming? connection 14.10 in-circuit debugger the pic16f882/883/884/886/887-icd can be used in any of the package types. the device will be mounted on the target application board, which in turn has a 3 or 4 wire connection to the icd tool. when the debug bit in the configuration word (config<13>) is programmed to a ? 0 ?, the in-circuit debugger functionality is enabled. this function allows simple debugging functions when used with mplab ? icd 2. when the microcontroller has this feature enabled, some of the resources are not available for general use. see table 14-9 for more detail. for more information, see ?using mplab ? icd 2? (ds51265), available on microchip?s web site (www.microchip.com). 14.10.1 icd pinout the devices in the pic16f88x family carry the circuitry for the in-circuit debugger on-chip and on existing device pins. this eliminates the need for a separate die or package for the icd device. the pinout for the icd device is the same as the devices (see section 1.0 ?device overview? for complete pinout and pin descriptions). table 14-9 shows the location and function of the icd related pins on the 28 and 40 pin devices. table 14-9: pic16f883/884/886/887-icd pin descriptions external connector signals to n o r m a l connections to n o r m a l connections pic16f882/883/ v dd v ss re3/mclr /v pp rb6 rb7 +5v 0v v pp clk data i/o * * * * * isolation devices (as required) 884/886/887 note: the user?s application must have the circuitry required to support icd functionality. once the icd circuitry is enabled, normal device pin functions on rb6/icspclk and rb7/icspdat will not be usable. the icd circuitry uses these pins for communication with the icd2 external debugger. pin (pdip) name type pull-up description pic16f884/887 pic16f882/883/ 886 40 28 icddata ttl ? in-circuit debugger bidirectional data 39 27 icdclk st ? in-circuit debugger bidirectional clock 11mclr /v pp hv ? programming voltage 11,32 20 v dd p? 12,31 8,19 v ss p? legend: ttl = ttl input buffer, st = schmitt trigger input buffer, p = power, hv = high voltage
? 2007 microchip technology inc. preliminary ds41291d-page 225 pic16f882/883/884/886/887 15.0 instruction set summary the pic16f883/884/886/887 instruction set is highly orthogonal and is comprised of three basic categories: ? byte-oriented operations ? bit-oriented operations ? literal and control operations each pic16 instruction is a 14-bit word divided into an opcode, which specifies the instruction type and one or more operands, which further specify the operation of the instruction. the formats for each of the categories is presented in figure 15-1, while the various opcode fields are summarized in table 15-1. table 15-2 lists the instructions recognized by the mpasm tm assembler. for byte-oriented instructions, ?f? represents a file register designator and ?d? represents a destination designator. the file register designator specifies which file register is to be used by the instruction. the destination designator specifies where the result of the operation is to be placed. if ?d? is zero, the result is placed in the w register. if ?d? is one, the result is placed in the file register specified in the instruction. for bit-oriented instructions, ?b? represents a bit field designator, which selects the bit affected by the operation, while ?f? represents the address of the file in which the bit is located. for literal and control operations, ?k? represents an 8-bit or 11-bit constant, or literal value. one instruction cycle consists of four oscillator periods; for an oscillator frequency of 4 mhz, this gives a normal instruction execution time of 1 s. all instructions are executed within a single instruction cycle, unless a conditional test is true, or the program counter is changed as a result of an instruction. when this occurs, the execution takes two instruction cycles, with the second cycle executed as a nop . all instruction examples use the format ? 0xhh ? to represent a hexadecimal number, where ? h ? signifies a hexadecimal digit. 15.1 read-modify-write operations any instruction that specifies a file register as part of the instruction performs a read-modify-write (rmw) operation. the register is read, the data is modified, and the result is stored according to either the instruc- tion, or the destination designator ?d?. a read operation is performed on a register even if the instruction writes to that register. for example, a clrf porta instruction will read porta, clear all the data bits, then write the result back to porta. this example would have the unintended consequence of clearing the condition that set the raif flag. table 15-1: opcode field descriptions figure 15-1: general format for instructions field description f register file address (0x00 to 0x7f) w working register (accumulator) b bit address within an 8-bit file register k literal field, constant data or label x don?t care location (= 0 or 1 ). the assembler will generate code with x = 0 . it is the recommended form of use for compatibility with all microchip software tools. d destination select; d = 0 : store result in w , d = 1 : store result in file register f. default is d = 1. pc program counter to time-out bit c carry bit dc digit carry bit z zero bit pd power-down bit byte-oriented file register operations 13 8 7 6 0 d = 0 for destination w opcode d f (file #) d = 1 for destination f f = 7-bit file register address bit-oriented file register operations 13 10 9 7 6 0 opcode b (bit #) f (file #) b = 3-bit bit address f = 7-bit file register address literal and control operations 13 8 7 0 opcode k (literal) k = 8-bit immediate value 13 11 10 0 opcode k (literal) k = 11-bit immediate value general call and goto instructions only
pic16f882/883/884/886/887 ds41291d-page 226 preliminary ? 2007 microchip technology inc. table 15-2: pic16f883/884/886/887 instruction set mnemonic, operands description cycles 14-bit opcode status affected notes msb lsb byte-oriented file register operations addwf andwf clrf clrw comf decf decfsz incf incfsz iorwf movf movwf nop rlf rrf subwf swapf xorwf f, d f, d f ? f, d f, d f, d f, d f, d f, d f, d f ? f, d f, d f, d f, d f, d add w and f and w with f clear f clear w complement f decrement f decrement f, skip if 0 increment f increment f, skip if 0 inclusive or w with f move f move w to f no operation rotate left f through carry rotate right f through carry subtract w from f swap nibbles in f exclusive or w with f 1 1 1 1 1 1 1 (2) 1 1 (2) 1 1 1 1 1 1 1 1 1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0111 0101 0001 0001 1001 0011 1011 1010 1111 0100 1000 0000 0000 1101 1100 0010 1110 0110 dfff dfff lfff 0xxx dfff dfff dfff dfff dfff dfff dfff lfff 0xx0 dfff dfff dfff dfff dfff ffff ffff ffff xxxx ffff ffff ffff ffff ffff ffff ffff ffff 0000 ffff ffff ffff ffff ffff c, dc, z z z z z z z z z c c c, dc, z z 1, 2 1, 2 2 1, 2 1, 2 1, 2, 3 1, 2 1, 2, 3 1, 2 1, 2 1, 2 1, 2 1, 2 1, 2 1, 2 bit-oriented file register operations bcf bsf btfsc btfss f, b f, b f, b f, b bit clear f bit set f bit test f, skip if clear bit test f, skip if set 1 1 1 (2) 1 (2) 01 01 01 01 00bb 01bb 10bb 11bb bfff bfff bfff bfff ffff ffff ffff ffff 1, 2 1, 2 3 3 literal and control operations addlw andlw call clrwdt goto iorlw movlw retfie retlw return sleep sublw xorlw k k k ? k k k ? k ? ? k k add literal and w and literal with w call subroutine clear watchdog timer go to address inclusive or literal with w move literal to w return from interrupt return with literal in w return from subroutine go into standby mode subtract w from literal exclusive or literal with w 1 1 2 1 2 1 1 2 2 2 1 1 1 11 11 10 00 10 11 11 00 11 00 00 11 11 111x 1001 0kkk 0000 1kkk 1000 00xx 0000 01xx 0000 0000 110x 1010 kkkk kkkk kkkk 0110 kkkk kkkk kkkk 0000 kkkk 0000 0110 kkkk kkkk kkkk kkkk kkkk 0100 kkkk kkkk kkkk 1001 kkkk 1000 0011 kkkk kkkk c, dc, z z to , p d z to , p d c, dc, z z note 1: when an i/o register is modified as a function of itself (e.g., movf gpio, 1 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as input and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tm r0 register (and where applicable, d = 1 ), the prescaler will be cleared if assigned to the timer0 module. 3: if the program counter (pc) is modified, or a conditional te st is true, the instruction requires two cycles. the second cycle is executed as a nop .
? 2007 microchip technology inc. preliminary ds41291d-page 227 pic16f882/883/884/886/887 15.2 instruction descriptions addlw add literal and w syntax: [ label ] addlw k operands: 0 k 255 operation: (w) + k (w) status affected: c, dc, z description: the contents of the w register are added to the eight-bit literal ?k? and the result is placed in the w register. addwf add w and f syntax: [ label ] addwf f,d operands: 0 f 127 d [ 0 , 1 ] operation: (w) + (f) (destination) status affected: c, dc, z description: add the contents of the w register with register ?f?. if ?d? is ? 0 ?, the result is stored in the w register. if ?d? is ? 1 ?, the result is stored back in register ?f?. andlw and literal with w syntax: [ label ] andlw k operands: 0 k 255 operation: (w) .and. (k) (w) status affected: z description: the contents of w register are and?ed with the eight-bit literal ?k?. the result is placed in the w register. andwf and w with f syntax: [ label ] andwf f,d operands: 0 f 127 d [ 0 , 1 ] operation: (w) .and. (f) (destination) status affected: z description: and the w register with register ?f?. if ?d? is ? 0 ?, the result is stored in the w register. if ?d? is ? 1 ?, the result is stored back in register ?f?. bcf bit clear f syntax: [ label ] bcf f,b operands: 0 f 127 0 b 7 operation: 0 (f) status affected: none description: bit ?b? in register ?f? is cleared. bsf bit set f syntax: [ label ] bsf f,b operands: 0 f 127 0 b 7 operation: 1 (f) status affected: none description: bit ?b? in register ?f? is set. btfsc bit test f, skip if clear syntax: [ label ] btfsc f,b operands: 0 f 127 0 b 7 operation: skip if (f) = 0 status affected: none description: if bit ?b? in register ?f? is ? 1 ?, the next instruction is executed. if bit ?b? in register ?f? is ? 0 ?, the next instruction is discarded, and a nop is executed instead, making this a two-cycle instruction.
pic16f882/883/884/886/887 ds41291d-page 228 preliminary ? 2007 microchip technology inc. btfss bit test f, skip if set syntax: [ label ] btfss f,b operands: 0 f 127 0 b < 7 operation: skip if (f) = 1 status affected: none description: if bit ?b? in register ?f? is ? 0 ?, the next instruction is executed. if bit ?b? is ? 1 ?, then the next instruction is discarded and a nop is executed instead, making this a two-cycle instruction. call call subroutine syntax: [ label ] call k operands: 0 k 2047 operation: (pc)+ 1 tos, k pc<10:0>, (pclath<4:3>) pc<12:11> status affected: none description: call subroutine. first, return address (pc + 1) is pushed onto the stack. the eleven-bit immediate address is loaded into pc bits <10:0>. the upper bits of the pc are loaded from pclath. call is a two-cycle instruction. clrf clear f syntax: [ label ] clrf f operands: 0 f 127 operation: 00h (f) 1 z status affected: z description: the contents of register ?f? are cleared and the z bit is set. clrw clear w syntax: [ label ] clrw operands: none operation: 00h (w) 1 z status affected: z description: w register is cleared. zero bit (z) is set. clrwdt clear watchdog timer syntax: [ label ] clrwdt operands: none operation: 00h wdt 0 wdt prescaler, 1 to 1 pd status affected: to , pd description: clrwdt instruction resets the watchdog timer. it also resets the prescaler of the wdt. status bits to and pd are set. comf complement f syntax: [ label ] comf f,d operands: 0 f 127 d [ 0 , 1 ] operation: (f ) (destination) status affected: z description: the contents of register ?f? are complemented. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f?. decf decrement f syntax: [ label ] decf f,d operands: 0 f 127 d [ 0 , 1 ] operation: (f) - 1 (destination) status affected: z description: decrement register ?f?. if ?d? is ? 0 ?, the result is stored in the w register. if ?d? is ? 1 ?, the result is stored back in register ?f?.
? 2007 microchip technology inc. preliminary ds41291d-page 229 pic16f882/883/884/886/887 decfsz decrement f, skip if 0 syntax: [ label ] decfsz f,d operands: 0 f 127 d [ 0 , 1 ] operation: (f) - 1 (destination); skip if result = 0 status affected: none description: the contents of register ?f? are decremented. if ?d? is ? 0 ?, the result is placed in the w register. if ?d? is ? 1 ?, the result is placed back in register ?f?. if the result is ? 1 ?, the next instruction is executed. if the result is ? 0 ?, then a nop is executed instead, making it a two-cycle instruction. goto unconditional branch syntax: [ label ] goto k operands: 0 k 2047 operation: k pc<10:0> pclath<4:3> pc<12:11> status affected: none description: goto is an unconditional branch. the eleven-bit immediate value is loaded into pc bits <10:0>. the upper bits of pc are loaded from pclath<4:3>. goto is a two-cycle instruction. incf increment f syntax: [ label ] incf f,d operands: 0 f 127 d [ 0 , 1 ] operation: (f) + 1 (destination) status affected: z description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in the w register. if ?d? is ? 1 ?, the result is placed back in register ?f?. incfsz increment f, skip if 0 syntax: [ label ] incfsz f,d operands: 0 f 127 d [ 0 , 1 ] operation: (f) + 1 (destination), skip if result = 0 status affected: none description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in the w register. if ?d? is ? 1 ?, the result is placed back in register ?f?. if the result is ? 1 ?, the next instruction is executed. if the result is ? 0 ?, a nop is executed instead, making it a two-cycle instruction. iorlw inclusive or literal with w syntax: [ label ] iorlw k operands: 0 k 255 operation: (w) .or. k (w) status affected: z description: the contents of the w register are or?ed with the eight-bit literal ?k?. the result is placed in the w register. iorwf inclusive or w with f syntax: [ label ] iorwf f,d operands: 0 f 127 d [ 0 , 1 ] operation: (w) .or. (f) (destination) status affected: z description: inclusive or the w register with register ?f?. if ?d? is ? 0 ?, the result is placed in the w register. if ?d? is ? 1 ?, the result is placed back in register ?f?.
pic16f882/883/884/886/887 ds41291d-page 230 preliminary ? 2007 microchip technology inc. movf move f syntax: [ label ] movf f,d operands: 0 f 127 d [ 0 , 1 ] operation: (f) (dest) status affected: z description: the contents of register ?f? is moved to a destination dependent upon the status of ?d?. if d = 0 , destination is w register. if d = 1 , the destination is file register ?f? itself. d = 1 is useful to test a file register since status flag z is affected. words: 1 cycles: 1 example : movf fsr, 0 after instruction w= value in fsr register z= 1 movlw move literal to w syntax: [ label ] movlw k operands: 0 k 255 operation: k (w) status affected: none description: the eight-bit literal ?k? is loaded into w register. the ?don?t cares? will assemble as ? 0 ?s. words: 1 cycles: 1 example : movlw 0x5a after instruction w= 0x5a movwf move w to f syntax: [ label ] movwf f operands: 0 f 127 operation: (w) (f) status affected: none description: move data from w register to register ?f?. words: 1 cycles: 1 example : movw f option before instruction option = 0xff w = 0x4f after instruction option = 0x4f w = 0x4f nop no operation syntax: [ label ] nop operands: none operation: no operation status affected: none description: no operation. words: 1 cycles: 1 example : nop
? 2007 microchip technology inc. preliminary ds41291d-page 231 pic16f882/883/884/886/887 retfie return from interrupt syntax: [ label ] retfie operands: none operation: tos pc, 1 gie status affected: none description: return from interrupt. stack is poped and top-of-stack (tos) is loaded in the pc. interrupts are enabled by setting global interrupt enable bit, gie (intcon<7>). this is a two-cycle instruction. words: 1 cycles: 2 example : retfie after interrupt pc = tos gie = 1 retlw return with literal in w syntax: [ label ] retlw k operands: 0 k 255 operation: k (w); tos pc status affected: none description: the w register is loaded with the eight-bit literal ?k?. the program counter is loaded from the top of the stack (the return address). this is a two-cycle instruction. words: 1 cycles: 2 example : table call table;w contains table ;offset value ? ;w now has ? ;table value ? ? addwf pc ;w = offset retlw k1 ;begin table retlw k2 ; ? ? ? retlw kn ;end of table before instruction w = 0x07 after instruction w = value of k8 return return from subroutine syntax: [ label ] return operands: none operation: tos pc status affected: none description: return from subroutine. the stack is poped and the top of the stack (tos) is loaded into the program counter. this is a two-cycle instruction.
pic16f882/883/884/886/887 ds41291d-page 232 preliminary ? 2007 microchip technology inc. rlf rotate left f through carry syntax: [ label ] rlf f,d operands: 0 f 127 d [ 0 , 1 ] operation: see description below status affected: c description: the contents of register ?f? are rotated one bit to the left through the carry flag. if ?d? is ? 0 ?, the result is placed in the w register. if ?d? is ? 1 ?, the result is stored back in register ?f?. words: 1 cycles: 1 example : rlf reg1,0 before instruction reg1 = 1110 0110 c=0 after instruction reg1 = 1110 0110 w = 1100 1100 c=1 rrf rotate right f through carry syntax: [ label ] rrf f,d operands: 0 f 127 d [ 0 , 1 ] operation: see description below status affected: c description: the contents of register ?f? are rotated one bit to the right through the carry flag. if ?d? is ? 0 ?, the result is placed in the w register. if ?d? is ? 1 ?, the result is placed back in register ?f?. register f c register f c sleep enter sleep mode syntax: [ label ] sleep operands: none operation: 00h wdt, 0 wdt prescaler, 1 to , 0 pd status affected: to , pd description: the power-down status bit, pd is cleared. time-out status bit, to is set. watchdog timer and its prescaler are cleared. the processor is put into sleep mode with the oscillator stopped. sublw subtract w from literal syntax: [ label ] sublw k operands: 0 k 255 operation: k - (w) ( w) status affected: c, dc, z description: the w register is subtracted (2?s complement method) from the eight-bit literal ?k?. the result is placed in the w register. c = 0 w > k c = 1 w k dc = 0 w<3:0> > k<3:0> dc = 1 w<3:0> k<3:0>
? 2007 microchip technology inc. preliminary ds41291d-page 233 pic16f882/883/884/886/887 subwf subtract w from f syntax: [ label ] subwf f,d operands: 0 f 127 d [ 0 , 1 ] operation: (f) - (w) ( destination) status affected: c, dc, z description: subtract (2?s complement method) w register from register ?f?. if ?d? is ? 0 ?, the result is stored in the w register. if ?d? is ? 1 ?, the result is stored back in register ?f?. swapf swap nibbles in f syntax: [ label ] swapf f,d operands: 0 f 127 d [ 0 , 1 ] operation: (f<3:0>) (destination<7:4>), (f<7:4>) (destination<3:0>) status affected: none description: the upper and lower nibbles of register ?f? are exchanged. if ?d? is ? 0 ?, the result is placed in the w register. if ?d? is ? 1 ?, the result is placed in register ?f?. xorlw exclusive or literal with w syntax: [ label ] xorlw k operands: 0 k 255 operation: (w) .xor. k ( w) status affected: z description: the contents of the w register are xor?ed with the eight-bit literal ?k?. the result is placed in the w register. c = 0 w > f c = 1 w f dc = 0 w<3:0> > f<3:0> dc = 1 w<3:0> f<3:0> xorwf exclusive or w with f syntax: [ label ] xorwf f,d operands: 0 f 127 d [ 0 , 1 ] operation: (w) .xor. (f) ( destination) status affected: z description: exclusive or the contents of the w register with register ?f?. if ?d? is ? 0 ?, the result is stored in the w register. if ?d? is ? 1 ?, the result is stored back in register ?f?.
pic16f882/883/884/886/887 ds41291d-page 234 preliminary ? 2007 microchip technology inc. notes:
? 2007 microchip technology inc. preliminary ds41291d-page 235 pic16f882/883/884/886/887 16.0 development support the pic ? microcontrollers are supported with a full range of hardware and software development tools: ? integrated development environment - mplab ? ide software ? assemblers/compilers/linkers - mpasm tm assembler - mplab c18 and mplab c30 c compilers -mplink tm object linker/ mplib tm object librarian - mplab asm30 assembler/linker/library ? simulators - mplab sim software simulator ?emulators - mplab ice 2000 in-circuit emulator - mplab real ice? in-circuit emulator ? in-circuit debugger - mplab icd 2 ? device programmers - picstart ? plus development programmer - mplab pm3 device programmer - pickit? 2 development programmer ? low-cost demonstration and development boards and evaluation kits 16.1 mplab integrated development environment software the mplab ide software brings an ease of software development previously unseen in the 8/16-bit micro- controller market. the mplab ide is a windows ? operating system-based application that contains: ? a single graphical interface to all debugging tools - simulator - programmer (sold separately) - emulator (sold separately) - in-circuit debugger (sold separately) ? a full-featured editor with color-coded context ? a multiple project manager ? customizable data windows with direct edit of contents ? high-level source code debugging ? visual device initializer for easy register initialization ? mouse over variable inspection ? drag and drop variables from source to watch windows ? extensive on-line help ? integration of select third party tools, such as hi-tech software c compilers and iar c compilers the mplab ide allows you to: ? edit your source files (either assembly or c) ? one touch assemble (or compile) and download to pic mcu emulator and simulator tools (automatically updates all project information) ? debug using: - source files (assembly or c) - mixed assembly and c - machine code mplab ide supports multiple debugging tools in a single development paradigm, from the cost-effective simulators, through low-cost in-circuit debuggers, to full-featured emulators. this eliminates the learning curve when upgrading to tools with increased flexibility and power.
pic16f882/883/884/886/887 ds41291d-page 236 preliminary ? 2007 microchip technology inc. 16.2 mpasm assembler the mpasm assembler is a full-featured, universal macro assembler for all pic mcus. the mpasm assembler generates relocatable object files for the mplink object linker, intel ? standard hex files, map files to detail memory usage and symbol reference, absolute lst files that contain source lines and generated machine code and coff files for debugging. the mpasm assembler features include: ? integration into mplab ide projects ? user-defined macros to streamline assembly code ? conditional assembly for multi-purpose source files ? directives that allow complete control over the assembly process 16.3 mplab c18 and mplab c30 c compilers the mplab c18 and mplab c30 code development systems are complete ansi c compilers for microchip?s pic18 and pic24 families of microcontrol- lers and the dspic30 and dspic33 family of digital sig- nal controllers. these compilers provide powerful integration capabilities, superior code optimization and ease of use not found with other compilers. for easy source level debugging, the compilers provide symbol information that is optimized to the mplab ide debugger. 16.4 mplink object linker/ mplib object librarian the mplink object linker combines relocatable objects created by the mpasm assembler and the mplab c18 c compiler. it can link relocatable objects from precompiled libraries, using directives from a linker script. the mplib object librarian manages the creation and modification of library files of precompiled code. when a routine from a library is called from a source file, only the modules that contain that routine will be linked in with the application. this allows large libraries to be used efficiently in many different applications. the object linker/library features include: ? efficient linking of single libraries instead of many smaller files ? enhanced code maintainability by grouping related modules together ? flexible creation of libraries with easy module listing, replacement, deletion and extraction 16.5 mplab asm30 assembler, linker and librarian mplab asm30 assembler produces relocatable machine code from symbolic assembly language for dspic30f devices. mplab c30 c compiler uses the assembler to produce its object file. the assembler generates relocatable object files that can then be archived or linked with other relocatable object files and archives to create an executable file. notable features of the assembler include: ? support for the entire dspic30f instruction set ? support for fixed-point and floating-point data ? command line interface ? rich directive set ? flexible macro language ? mplab ide compatibility 16.6 mplab sim software simulator the mplab sim software simulator allows code development in a pc-hosted environment by simulat- ing the pic mcus and dspic ? dscs on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a comprehensive stimulus controller. registers can be logged to files for further run-time analysis. the trace buffer and logic analyzer display extend the power of the simulator to record and track program execution, actions on i/o, most peripherals and internal registers. the mplab sim software simulator fully supports symbolic debugging using the mplab c18 and mplab c30 c compilers, and the mpasm and mplab asm30 assemblers. the software simulator offers the flexibility to develop and debug code outside of the hardware laboratory environment, making it an excellent, economical software development tool.
? 2007 microchip technology inc. preliminary ds41291d-page 237 pic16f882/883/884/886/887 16.7 mplab ice 2000 high-performance in-circuit emulator the mplab ice 2000 in-circuit emulator is intended to provide the product development engineer with a complete microcontroller design tool set for pic microcontrollers. software control of the mplab ice 2000 in-circuit emulator is advanced by the mplab integrated development environment, which allows editing, building, downloading and source debugging from a single environment. the mplab ice 2000 is a full-featured emulator system with enhanced trace, trigger and data monitor- ing features. interchangeable processor modules allow the system to be easily reconfigured for emulation of different processors. the architecture of the mplab ice 2000 in-circuit emulator allows expansion to support new pic microcontrollers. the mplab ice 2000 in-circuit emulator system has been designed as a real-time emulation system with advanced features that are typically found on more expensive development tools. the pc platform and microsoft ? windows ? 32-bit operating system were chosen to best make these features available in a simple, unified application. 16.8 mplab real ice in-circuit emulator system mplab real ice in-circuit emulator system is microchip?s next generation high-speed emulator for microchip flash dsc ? and mcu devices. it debugs and programs pic ? and dspic ? flash microcontrollers with the easy-to-use, powerful graphical user interface of the mplab integrated development environment (ide), included with each kit. the mplab real ice probe is connected to the design engineer?s pc using a high-speed usb 2.0 interface and is connected to the target with either a connector compatible with the popular mplab icd 2 system (rj11) or with the new high speed, noise tolerant, low- voltage differential signal (lvds) interconnection (cat5). mplab real ice is field upgradeable through future firmware downloads in mplab ide. in upcoming releases of mplab ide, new devices will be supported, and new features will be added, such as software break- points and assembly code trace. mplab real ice offers significant advantages over competitive emulators including low-cost, full-speed emulation, real-time variable watches, trace analysis, complex breakpoints, a ruggedized probe interface and long (up to three meters) interconnection cables. 16.9 mplab icd 2 in-circuit debugger microchip?s in-circuit debugger, mplab icd 2, is a powerful, low-cost, run-time development tool, connecting to the host pc via an rs-232 or high-speed usb interface. this tool is based on the flash pic mcus and can be used to develop for these and other pic mcus and dspic dscs. the mplab icd 2 utilizes the in-circuit debugging capability built into the flash devices. this feature, along with microchip?s in-circuit serial programming tm (icsp tm ) protocol, offers cost- effective, in-circuit flash debugging from the graphical user interface of the mplab integrated development environment. this enables a designer to develop and debug source code by setting breakpoints, single step- ping and watching variables, and cpu status and peripheral registers. running at full speed enables testing hardware and applications in real time. mplab icd 2 also serves as a development programmer for selected pic devices. 16.10 mplab pm3 device programmer the mplab pm3 device programmer is a universal, ce compliant device programmer with programmable voltage verification at v ddmin and v ddmax for maximum reliability. it features a large lcd display (128 x 64) for menus and error messages and a modu- lar, detachable socket assembly to support various package types. the icsp? cable assembly is included as a standard item. in stand-alone mode, the mplab pm3 device programmer can read, verify and program pic devices without a pc connection. it can also set code protection in this mode. the mplab pm3 connects to the host pc via an rs-232 or usb cable. the mplab pm3 has high-speed communications and optimized algorithms for quick programming of large memory devices and incorporates an sd/mmc card for file storage and secure data applications.
pic16f882/883/884/886/887 ds41291d-page 238 preliminary ? 2007 microchip technology inc. 16.11 picstart plus development programmer the picstart plus development programmer is an easy-to-use, low-cost, prototype programmer. it connects to the pc via a com (rs-232) port. mplab integrated development environment software makes using the programmer simple and efficient. the picstart plus development programmer supports most pic devices in dip packages up to 40 pins. larger pin count devices, such as the pic16c92x and pic17c76x, may be supported with an adapter socket. the picstart plus development programmer is ce compliant. 16.12 pickit 2 development programmer the pickit? 2 development programmer is a low-cost programmer and selected flash device debugger with an easy-to-use interface for programming many of microchip?s baseline, mid-range and pic18f families of flash memory microcontrollers. the pickit 2 starter kit includes a prototyping development board, twelve sequential lessons, software and hi-tech?s picc? lite c compiler, and is designed to help get up to speed quickly using pic ? microcontrollers. the kit provides everything needed to program, evaluate and develop applications using microchip?s powerful, mid-range flash memory family of microcontrollers. 16.13 demonstration, development and evaluation boards a wide variety of demonstration, development and evaluation boards for various pic mcus and dspic dscs allows quick application development on fully func- tional systems. most boards include prototyping areas for adding custom circuitry and provide application firmware and source code for examination and modification. the boards support a variety of features, including leds, temperature sensors, switches, speakers, rs-232 interfaces, lcd displays, potentiometers and additional eeprom memory. the demonstration and development boards can be used in teaching environments, for prototyping custom circuits and for learning about various microcontroller applications. in addition to the picdem? and dspicdem? demon- stration/development board series of circuits, microchip has a line of evaluation kits and demonstration software for analog filter design, k ee l oq ? security ics, can, irda ? , powersmart ? battery management, seeval ? evaluation system, sigma-delta adc, flow rate sensing, plus many more. check the microchip web page (www.microchip.com) and the latest ?product selector guide? (ds00148) for the complete list of demonstration, development and evaluation kits.
? 2007 microchip technology inc. preliminary ds41291d-page 239 pic16f882/883/884/886/887 17.0 electrical specifications absolute maximum ratings (?) ambient temperature under bias................................................................................................. .........-40 to +125c storage temperature ............................................................................................................ ............ -65c to +150c voltage on v dd with respect to v ss ................................................................................................... -0.3v to +6.5v voltage on mclr with respect to vss ............................................................................................... -0.3v to +1 3.5v voltage on all other pins with respect to v ss ........................................................................... -0.3v to (v dd + 0.3v) total power dissipation (1) ............................................................................................................................... 800 mw maximum current out of v ss pin .................................................................................................................... 300 ma maximum current into v dd pin ....................................................................................................................... 250 ma input clamp current, i ik (v i < 0 or v i > v dd ) ............................................................................................................... 20 ma output clamp current, i ok (vo < 0 or vo >v dd ) ......................................................................................................... 20 ma maximum output current sunk by any i/o pin..................................................................................... ............... 25 ma maximum output current sourced by any i/o pin .................................................................................. ............ 25 ma maximum current sunk by porta, portb and porte (combined) (2) ........................................................ 200 ma maximum current sourced by porta, portb and porte (combined) (2) .................................................. 200 ma maximum current sunk by portc and portd (combined) (2) ..................................................................... 200 ma maximum current sourced by portc and portd (combined) (2) ................................................................ 200 ma note 1: power dissipation is calculated as follows: p dis = v dd x {i dd ? i oh } + {(v dd ? v oh ) x i oh } + (v o l x i ol ). 2: portd and porte are implemented on pic16f886/pic16f887 only. ? notice: stresses above those listed under ?absolute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the device at those or any other conditions above those indicated in the operation listings of this specification is not implied. exposure above maximum rating conditions for extended periods may affect device reliability.
pic16f882/883/884/886/887 ds41291d-page 240 preliminary ? 2007 microchip technology inc. figure 17-1: pic16f882/883/884/886/887 voltage-frequency graph, -40c t a +125c figure 17-2: hfintosc frequency accuracy over device v dd and temperature 5.5 2.0 3.5 2.5 0 3.0 4.0 4.5 5.0 frequency (mhz) v dd (v) note 1: the shaded region indicates the permissible combinations of voltage and frequency. 820 10 125 25 2.0 0 60 85 v dd (v) 4.0 5.0 4.5 temperature ( c ) 2.5 3.0 3.5 5.5 1% 2% 5%
? 2007 microchip technology inc. preliminary ds41291d-page 241 pic16f882/883/884/886/887 17.1 dc characteristics: pic16f882/883/884/886/887-i (industrial) pic16f882/883/884/886/887-e (extended) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. sym characteristic min typ? max units conditions d001 d001c d001d v dd supply voltage 2.0 2.0 3.0 4.5 ? ? ? ? 5.5 5.5 5.5 5.5 v v v v f osc < = 8 mhz: hfintosc, ec f osc < = 4 mhz f osc < = 10 mhz f osc < = 20 mhz d002* v dr ram data retention voltage (1) 1.5 ? ? v device in sleep mode d003 v por v dd start voltage to ensure internal power-on reset signal ?v ss ?vsee section 14.2.1 ?power-on reset (por)? for details. d004* s vdd v dd rise rate to ensure internal power-on reset signal 0.05 ? ? v/ms see section 14.2.1 ?power-on reset (por)? for details. * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: this is the limit to which v dd can be lowered in sleep mode without losing ram data.
pic16f882/883/884/886/887 ds41291d-page 242 preliminary ? 2007 microchip technology inc. 17.2 dc characteristics: pic16f882/883/884/886/887-i (industrial) pic16f882/883/884/886/887-e (extended) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. device characteristics min typ? max units conditions v dd note d010 supply current (i dd ) (1, 2) ?11 23 a2.0f osc = 32 khz lp oscillator mode ?18 38 a3.0 ?35 75 a5.0 d011* ? 140 250 a2.0f osc = 1 mhz xt oscillator mode ? 220 400 a3.0 ? 380 650 a5.0 d012 ? 260 380 a2.0f osc = 4 mhz xt oscillator mode ? 420 670 a3.0 ?0.81.4ma5.0 d013* ? 130 220 a2.0f osc = 1 mhz ec oscillator mode ? 215 360 a3.0 ? 360 520 a5.0 d014 ? 220 340 a2.0f osc = 4 mhz ec oscillator mode ? 375 550 a3.0 ? 0.65 1.0 ma 5.0 d015 ? 8 20 a2.0f osc = 31 khz lfintosc mode ?16 40 a3.0 ?31 65 a5.0 d016* ? 340 400 a2.0f osc = 4 mhz hfintosc mode ? 500 650 a3.0 ?0.81.2ma5.0 d017 ? 410 0.7 a2.0f osc = 8 mhz hfintosc mode ? 700 1 a3.0 ? 1.30 1.8 ma 5.0 d018 ? 230 580 a2.0f osc = 4 mhz extrc mode (3) ? 400 950 a3.0 ? 0.63 1.6 ma 5.0 d019 ? 2.6 3.7 ma 4.5 f osc = 20 mhz hs oscillator mode ?2.83.8ma5.0 * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd ; mclr = v dd ; wdt disabled. 2: the supply current is mainly a function of the operating voltage and frequency. other factors, such as i/o pin loading and switching rate, oscillator type, internal code execution pattern and temperature, also have an impact on the current consumption. 3: for rc oscillator configurations, current through r ext is not included. the current through the resistor can be extended by the formula i r = v dd /2r ext (ma) with r ext in k .
? 2007 microchip technology inc. preliminary ds41291d-page 243 pic16f882/883/884/886/887 17.3 dc characteristics: pic16f882/883/884/886/887-i (industrial) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device characteristics min typ? max units conditions v dd note d020 power-down base current(i pd ) (2) ? 0.05 1.2 a 2.0 wdt, bor, comparators, v ref and t1osc disabled ? 0.15 1.5 a3.0 ? 0.35 1.8 a5.0 ? 150 500 na 3.0 -40c t a +25c d021 ? 1.0 2.2 a 2.0 wdt current (1) ?2.04.0 a3.0 ?3.07.0 a5.0 d022 ? 42 60 a 3.0 bor current (1) ? 85 122 a5.0 d023 ? 32 45 a 2.0 comparator current (1) , both comparators enabled ?6078 a3.0 ? 120 160 a5.0 d024 ? 30 36 a2.0cv ref current (1) (high range) ?4555 a3.0 ?7595 a5.0 d025* ? 39 47 a2.0cv ref current (1) (low range) ?5972 a3.0 ? 98 124 a5.0 d026 ? 4.5 7.0 a 2.0 t1osc current (1) , 32.768 khz ?5.08.0 a3.0 ?6.0 12 a5.0 d027 ? 0.30 1.6 a 3.0 a/d current (1) , no conversion in progress ? 0.36 1.9 a5.0 * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: the peripheral current is the sum of the base i dd or i pd and the additional current consumed when this peripheral is enabled. the peripheral current can be determined by subtracting the base i dd or i pd current from this limit. max values should be used when calculating total current consumption. 2: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd .
pic16f882/883/884/886/887 ds41291d-page 244 preliminary ? 2007 microchip technology inc. 17.4 dc characteristics: pic16f882/883/884/886/887 -e (extended) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c for extended param no. device characteristics min typ? max units conditions v dd note d020e power-down base current (i pd ) (2) ?0.05 9 a 2.0 wdt, bor, comparators, v ref and t1osc disabled ?0.15 11 a3.0 ?0.35 15 a5.0 d021e ? 1 28 a 2.0 wdt current (1) ?2 30 a3.0 ?3 35 a5.0 d022e ? 42 65 a 3.0 bor current (1) ?85127 a5.0 d023e ? 32 45 a 2.0 comparator current (1) , both comparators enabled ?60 78 a3.0 ?120160 a5.0 d024e ? 30 70 a2.0cv ref current (1) (high range) ?45 90 a3.0 ?75120 a5.0 d025e* ? 39 91 a2.0cv ref current (1) (low range) ?59117 a3.0 ?98156 a5.0 d026e ? 4.5 25 a 2.0 t1osc current (1) , 32.768 khz ?5 30 a3.0 ?6 40 a5.0 d027e ? 0.30 12 a 3.0 a/d current (1) , no conversion in progress ?0.36 16 a5.0 * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: the peripheral current is the sum of the base i dd or i pd and the additional current consumed when this peripheral is enabled. the peripheral current can be determined by subtracting the base i dd or i pd current from this limit. max values should be used when calculating total current consumption. 2: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd .
? 2007 microchip technology inc. preliminary ds41291d-page 245 pic16f882/883/884/886/887 17.5 dc characteristics: pic16f882/883/884/886/887-i (industrial) pic16f882/883/884/886/887-e (extended) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. sym characteristic min typ? max units conditions v il input low voltage i/o port: d030 with ttl buffer vss ? 0.8 v 4.5v v dd 5.5v d030a vss ? 0.15 v dd v2.0v v dd 4.5v d031 with schmitt trigger buffer vss ? 0.2 v dd v2.0v v dd 5.5v d032 mclr , osc1 (rc mode) (1) v ss ?0.2 v dd v d033 osc1 (xt and lp modes) v ss ?0.3v d033a osc1 (hs mode) v ss ?0.3 v dd v v ih input high voltage i/o ports: ? d040 with ttl buffer 2.0 ? v dd v4.5v v dd 5.5v d040a 0.25 v dd + 0.8 ? v dd v2.0v v dd 4.5v d041 with schmitt trigger buffer 0.8 v dd ?v dd v2.0v v dd 5.5v d042 mclr 0.8 v dd ?v dd v d043 osc1 (xt and lp modes) 1.6 ? v dd v d043a osc1 (hs mode) 0.7 v dd ?v dd v d043b osc1 (rc mode) 0.9 v dd ?v dd v (note 1) i il input leakage current (2) d060 i/o ports ? 0.1 1 av ss v pin v dd , pin at high-impedance d061 mclr (3) ? 0.1 5 av ss v pin v dd d063 osc1 ? 0.1 5 av ss v pin v dd , xt, hs and lp oscillator configuration d070* i pur porta weak pull-up current 50 250 400 av dd = 5.0v, v pin = v ss v ol output low voltage (5) d080 i/o ports ? ? 0.6 v i ol = 8.5 ma, v dd = 4.5v (ind.) v oh output high voltage (5) d090 i/o ports v dd ? 0.7 ? ? v i oh = -3.0 ma, v dd = 4.5v (ind.) * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: in rc oscillator configuration, the osc1 /clkin pin is a schmitt trigger input. it is not recommended to use an external clock in rc mode. 2: negative current is defined as current sourced by the pin. 3: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 4: see section 10.3.1 ?using the data eeprom? for additional information. 5: including osc2 in clkout mode.
pic16f882/883/884/886/887 ds41291d-page 246 preliminary ? 2007 microchip technology inc. d100 i ulp ultra low-power wake-up current ? 200 ? na see application note an879, ? using the microchip ultra low-power wake-up module ? (ds00879) capacitive loading specs on output pins d101* cosc2 osc2 pin ? ? 15 pf in xt, hs and lp modes when external clock is used to drive osc1 d101a* c io all i/o pins ? ? 50 pf data eeprom memory d120 e d byte endurance 100k 1m ? e/w -40c t a +85c d120a e d byte endurance 10k 100k ? e/w +85c t a +125c d121 v drw v dd for read/write v min ? 5.5 v using eecon1 to read/write v min = minimum operating voltage d122 t dew erase/write cycle time ? 5 6 ms d123 t retd characteristic retention 40 ? ? year provided no other specifications are violated d124 t ref number of total erase/write cycles before refresh (4) 1m 10m ? e/w -40c t a +85c program flash memory d130 e p cell endurance 10k 100k ? e/w -40c t a +85c d130a e d cell endurance 1k 10k ? e/w +85c t a +125c d131 v pr v dd for read v min ?5.5vv min = minimum operating voltage d132 v pew v dd for erase/write 4.5 ? 5.5 v d133 t pew erase/write cycle time ? 2 2.5 ms d134 t retd characteristic retention 40 ? ? year provided no other specifications are violated 17.5 dc characteristics: pic16f882/883/884/886/887-i (industrial) pic16f882/883/884/886/887-e (extended) (continued) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. sym characteristic min typ? max units conditions * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: in rc oscillator configuration, the osc1 /clkin pin is a schmitt trigger input. it is not recommended to use an external clock in rc mode. 2: negative current is defined as current sourced by the pin. 3: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 4: see section 10.3.1 ?using the data eeprom? for additional information. 5: including osc2 in clkout mode.
? 2007 microchip technology inc. preliminary ds41291d-page 247 pic16f882/883/884/886/887 17.6 thermal considerations standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c param no. sym characteristic typ units conditions th01 ja thermal resistance junction to ambient 47.2 c/w 40-pin pdip package 24.4 c/w 44-pin qfn package 45.8 c/w 44-pin tqfp package 60.2 c/w 28-pin pdip package 80.2 c/w 28-pin soic package 89.4 c/w 28-pin ssop package 29 c/w 28-pin qfn package th02 jc thermal resistance junction to case 24.7 c/w 40-pin pdip package tbd c/w 44-pin qfn package 14.5 c/w 44-pin tqfp package 29 c/w 28-pin pdip package 23.8 c/w 28-pin soic package 23.9 c/w 28-pin ssop package tbd c/w 28-pin qfn package th03 t j junction temperature 150 c for derated power calculations th04 pd power dissipation ? w pd = p internal + p i / o th05 p internal internal power dissipation ? w p internal = i dd x v dd (note 1) th06 p i / o i/o power dissipation ? w p i / o = (i ol * v ol ) + (i oh * (v dd - v oh )) th07 p der derated power ? w p der = (t j - t a )/ ja (note 2, 3) legend: tbd = to be determined. note 1: i dd is current to run the chip alone without driving any load on the output pins. 2: t a = ambient temperature. 3: maximum allowable power dissipation is the lower value of either the absolute maximum total power dissipation or derated power (p der ).
pic16f882/883/884/886/887 ds41291d-page 248 preliminary ? 2007 microchip technology inc. 17.7 timing parameter symbology the timing parameter symbols have been created with one of the following formats: figure 17-3: load conditions 1. tpps2pps 2. tpps t f frequency t time lowercase letters (pp) and their meanings: pp cc ccp1 osc osc1 ck clkout rd rd cs cs rw rd or wr di sdi sc sck do sdo ss ss dt data in t0 t0cki io i/o port t1 t1cki mc mclr wr wr uppercase letters and their meanings: s ffall pperiod hhigh rrise i invalid (high-impedance) v valid l low z high-impedance v ss c l legend: c l = 50 pf for all pins 15 pf for osc2 output load condition pin
? 2007 microchip technology inc. preliminary ds41291d-page 249 pic16f882/883/884/886/887 17.8 ac characteristics: pic16f882/883/884/886/887 (industrial, extended) figure 17-4: clock timing table 17-1: clock oscillator timing requirements standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c param no. sym characteristic min typ? max units conditions os01 f osc external clkin frequency (1) dc ? 37 khz lp oscillator mode dc ? 4 mhz xt oscillator mode dc ? 20 mhz hs oscillator mode dc ? 20 mhz ec oscillator mode oscillator frequency (1) ? 32.768 ? khz lp oscillator mode 0.1 ? 4 mhz xt oscillator mode 1 ? 20 mhz hs oscillator mode dc ? 4 mhz rc oscillator mode os02 t osc external clkin period (1) 27 ? ? s lp oscillator mode 250 ? ? ns xt oscillator mode 50 ? ? ns hs oscillator mode 50 ? ? ns ec oscillator mode oscillator period (1) ?30.5 ? s lp oscillator mode 250 ? 10,000 ns xt oscillator mode 50 ? 1,000 ns hs oscillator mode 250 ? ? ns rc oscillator mode os03 t cy instruction cycle time (1) 200 t cy dc ns t cy = 4/f osc os04* tosh, tos l external clkin high, external clkin low 2?? s lp oscillator 100 ? ? ns xt oscillator 20 ? ? ns hs oscillator os05* tosr, tos f external clkin rise, external clkin fall 0 ? ? ns lp oscillator 0 ? ? ns xt oscillator 0 ? ? ns hs oscillator * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: instruction cycle period (t cy ) equals four times the input oscillator time base period. all specified values are based on characterization data for that particular oscillator type under standard operating conditions with the device executing code. exceeding these specified limits may result in an unstable oscillator operation and/or higher than expected current consumption. all devices are tested to operate at ?min? values with an external clock applied to osc1 pin. when an external clock input is used, the ?max? cycle time limit is ?dc? (no clock) for all devices. osc1/clkin osc2/clkout q4 q1 q2 q3 q4 q1 os02 os03 os04 os04 osc2/clkout (lp,xt,hs modes) (clkout mode)
pic16f882/883/884/886/887 ds41291d-page 250 preliminary ? 2007 microchip technology inc. table 17-2: oscillator parameters standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c param no. sym characteristic freq tolerance min typ? max units conditions os06 t warm internal oscillator switch when running (3) ???2t osc slowest clock os07 t sc fail-safe sample clock period (1) ? ?21?mslfintosc/64 os08 hf osc internal calibrated hfintosc frequency (2) 1% 7.92 8.0 8.08 mhz v dd = 3.5v, 25c 2% 7.84 8.0 8.16 mhz 2.5v v dd 5.5v, 0c t a +85c 5% 7.60 8.0 8.40 mhz 2.0v v dd 5.5v, -40c t a +85c (ind.), -40c t a +125c (ext.) os09* lf osc internal uncalibrated lfintosc frequency ? 153145khz os10* t iosc st hfintosc oscillator wake-up from sleep start-up time ? 5.5 12 24 sv dd = 2.0v, -40c to +85c ?3.5714 sv dd = 3.0v, -40c to +85c ?3611 sv dd = 5.0v, -40c to +85c * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: instruction cycle period (t cy ) equals four times the input oscillator time base period. all specified values are based on characterization data for that particular oscillator type under standard operating conditions with the device executing code. exceeding these specified limits may result in an unstable oscillator operation and/or higher than expected current consumption. all devices are tested to operate at ?min? values with an external clock applied to the osc1 pin. when an external clock input is used, the ?max? cycle time limit is ?dc? (no clock) for all devices. 2: to ensure these oscillator frequency tolerances, v dd and v ss must be capacitively decoupled as close to the device as possible. 0.1 f and 0.01 f values in parallel are recommended. 3: by design.
? 2007 microchip technology inc. preliminary ds41291d-page 251 pic16f882/883/884/886/887 figure 17-5: clkout and i/o timing f osc clkout i/o pin (input) i/o pin (output) q4 q1 q2 q3 os11 os19 os13 os15 os18, os19 os20 os21 os17 os16 os14 os12 os18 old value new value write fetch read execute cycle table 17-3: clkout and i/o timing parameters standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c param no. sym characteristic min typ? max units conditions os11 t os h2 ck lf osc to clkout (1) ? ? 70 ns v dd = 5.0v os12 t os h2 ck hf osc to clkout (1) ? ? 72 ns v dd = 5.0v os13 t ck l2 io vclkout to port out valid (1) ? ? 20 ns os14 t io v2 ck h port input valid before clkout (1) t osc + 200 ns ? ? ns os15* t os h2 io vf osc (q1 cycle) to port out valid ? 50 70 ns v dd = 5.0v os16 t os h2 io if osc (q2 cycle) to port input invalid (i/o in hold time) 50 ? ? ns v dd = 5.0v os17 t io v2 os h port input valid to f osc (q2 cycle) (i/o in setup time) 20 ? ? ns os18 t io r port output rise time (2) ? ? 15 40 72 32 ns v dd = 2.0v v dd = 5.0v os19 t io f port output fall time (2) ? ? 28 15 55 30 ns v dd = 2.0v v dd = 5.0v os20* t inp int pin input high or low time 25 ? ? ns os21* t rap porta interrupt-on-change new input level time t cy ??ns * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25 c unless otherwise stated. note 1: measurements are taken in rc mode where clkout output is 4 x t osc . 2: includes osc2 in clkout mode.
pic16f882/883/884/886/887 ds41291d-page 252 preliminary ? 2007 microchip technology inc. figure 17-6: reset, watchdog timer, oscillator start-up timer and power-up timer timing figure 17-7: brown-out rese t timing and characteristics v dd mclr internal por pwrt time-out osc start-up time internal reset (1) watchdog timer 33 32 30 31 34 i/o pins 34 note 1: asserted low. reset (1) v bor v dd (device in brown-out reset) (device not in brown-out reset) 33* 37 * 64 ms delay only if pwrte bit in the configuration word register 1 is programmed to ? 0 ?. reset (due to bor) v bor + v hyst
? 2007 microchip technology inc. preliminary ds41291d-page 253 pic16f882/883/884/886/887 table 17-4: reset, watchdog timer, oscillator start-up timer, power-up timer and brown-out reset parameters standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c param no. sym characteristic min typ? max units conditions 30 t mc lmclr pulse width (low) 2 5 ? ? ? ? s s v dd = 5v, -40c to +85c v dd = 5v 31 t wdt watchdog timer time-out period (no prescaler) 10 10 16 16 29 31 ms ms v dd = 5v, -40c to +85c v dd = 5v 32 t ost oscillation start-up timer period (1, 2) ? 1024 ? t osc (note 3) 33* t pwrt power-up timer period 40 65 140 ms 34* t ioz i/o high-impedance from mclr low or watchdog timer reset ??2.0 s 35 v bor brown-out reset voltage 2.0 ? 2.2 v bor4v bit = 0 (note 4) 35 v bor brown-out reset voltage tbd 4.0 tbd vbor4v bit = 1 (note 4) 36* v hyst brown-out reset hysteresis ? 50 ? mv 37* t bor brown-out reset minimum detection period 100 ? ? sv dd v bor * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: instruction cycle period (t cy ) equals four times the input oscillator time base period. all specified values are based on characterization data for that particular oscillator type under standard operating conditions with the device executing code. exceeding these specified limits may result in an unstable oscillator oper- ation and/or higher than expected current consumption. all devices are tested to operate at ?min? values with an external clock applied to the osc1 pin. when an external clock input is used, the ?max? cycle time limit is ?dc? (no clock) for all devices. 2: by design. 3: period of the slower clock. 4: to ensure these voltage tolerances, v dd and v ss must be capacitively decoupled as close to the device as possible. 0.1 f and 0.01 f values in parallel are recommended.
pic16f882/883/884/886/887 ds41291d-page 254 preliminary ? 2007 microchip technology inc. figure 17-8: timer0 and timer1 external clock timings table 17-5: timer0 and timer1 external clock requirements standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c param no. sym characteristic min typ? max units conditions 40* t t 0h t0cki high pulse width no prescaler 0.5 t cy + 20 ? ? ns with prescaler 10 ? ? ns 41* t t 0l t0cki low pulse width no prescaler 0.5 t cy + 20 ? ? ns with prescaler 10 ? ? ns 42* t t 0p t0cki period greater of: 20 or t cy + 40 n ? ? ns n = prescale value (2, 4, ..., 256) 45* t t 1h t1cki high time synchronous, no prescaler 0.5 t cy + 20 ? ? ns synchronous, with prescaler 15 ? ? ns asynchronous 30 ? ? ns 46* t t 1l t1cki low time synchronous, no prescaler 0.5 t cy + 20 ? ? ns synchronous, with prescaler 15 ? ? ns asynchronous 30 ? ? ns 47* t t 1p t1cki input period synchronous greater of: 30 or t cy + 40 n ? ? ns n = prescale value (1, 2, 4, 8) asynchronous 60 ? ? ns 48 f t 1 timer1 oscillator input frequency range (oscillator enabled by setting bit t1oscen) ? 32.768 ? khz 49* tckez tmr 1 delay from external clock edge to timer increment 2 t osc ?7 t osc ? timers in sync mode * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise stat ed. these parameters are for design guidance only and are not tested. t0cki t1cki 40 41 42 45 46 47 49 tmr0 or tmr1
? 2007 microchip technology inc. preliminary ds41291d-page 255 pic16f882/883/884/886/887 figure 17-9: capture/compare/pwm timings (eccp) table 17-6: capture/compare/pwm requirements (eccp) standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c param no. sym characteristic min typ? max units conditions cc01* tccl ccp1 input low time no prescaler 0.5t cy + 20 ? ? ns with prescaler 20 ? ? ns cc02* tcch ccp1 input high time no prescaler 0.5t cy + 20 ? ? ns with prescaler 20 ? ? ns cc03* tccp ccp1 input period 3t cy + 40 n ? ? ns n = prescale value (1, 4 or 16) * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note: refer to figure 17-3 for load conditions. (capture mode) cc01 cc02 cc03 ccp1
pic16f882/883/884/886/887 ds41291d-page 256 preliminary ? 2007 microchip technology inc. table 17-7: comparator specifications table 17-8: comparator voltage reference (cv ref ) specifications standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c param no. sym characteristics min typ? max units comments cm01 v os input offset voltage ? 5.0 10 mv (v dd - 1.5)/2 cm02 v cm input common mode voltage 0 ? v dd - 1.5 v cm03* c mrr common mode rejection ratio +55 ? ? db cm04* t rt response time falling ? 150 600 ns (note 1) rising ? 200 1000 ns cm05* t mc 2 co v comparator mode change to output valid ?? 10 s * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: response time is measured with one comparator input at (v dd - 1.5)/2 - 100 mv to (v dd -1.5)/2+20mv. standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c param no. sym characteristics min typ? max units comments cv01* c lsb step size (2) ? ? v dd /24 v dd /32 ? ? v v low range (vrr = 1 ) high range (vrr = 0 ) cv02* c acc absolute accuracy ? ? ? ? 1/2 1/2 lsb lsb low range (vrr = 1 ) high range (vrr = 0 ) cv03* c r unit resistor value (r) ? 2k ? cv04* c st settling time (1) ??10 s * these parameters are characterized but not tested. ? data in ?typ? column is at 5v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: settling time measured while vrr = 1 and vr<3:0> transitions from ? 0000 ? to ? 1111 ?. 2: see section 8.10 ?comparator voltage reference? for more information.
? 2007 microchip technology inc. preliminary ds41291d-page 257 pic16f882/883/884/886/887 table 17-9: pic16f882/883/884/886/88 7 a/d converter (adc) characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c param no. sym characteristic min typ? max units conditions ad01 n r resolution ? ? 10 bits bit ad02 e il integral error ? ? 1 lsb v ref = 5.12v ad03 e dl differential error ? ? 1 lsb no missing codes to 10 bits v ref = 5.12v ad04 e off offset error ? 1.5 tbd lsb v ref = 5.12v ad07 e gn gain error ? 1 tbd lsb v ref = 5.12v ad06 ad06a v ref reference voltage (3) 2.2 2.7 ?? v dd v absolute minimum to ensure 1 lsb accuracy ad07 v ain full-scale range v ss ?v ref v ad08 z ain recommended impedance of analog voltage source ?? 10k ad09* i ref v ref input current (3) 10 ? 1000 aduring v ain acquisition. based on differential of v hold to v ain . ?? 50 a during a/d conversion cycle. legend: tbd = to be determined. * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: total absolute error includes integral, differential, offset and gain errors. 2: the a/d conversion result never decreases with an increase in the input voltage and has no missing codes. 3: adc v ref is from external v ref or v dd pin, whichever is selected as reference input. 4: when adc is off, it will not consume any current other than leakage current. the power-down current specification includes any such leakage from the adc module.
pic16f882/883/884/886/887 ds41291d-page 258 preliminary ? 2007 microchip technology inc. table 17-10: pic16f882/883/884/886/887 a/d conversion requirements standard operating conditions (unless otherwise stated) operating temperature -40c t a +125c param no. sym characteristic min typ? max units conditions ad130* t ad a/d clock period 1.6 ? 9.0 st osc -based, v ref 3.0v 3.0 ? 9.0 st osc -based, v ref full range a/d internal rc oscillator period 3.0 6.0 9.0 s adcs<1:0> = 11 (adrc mode) at v dd = 2.5v 1.6 4.0 6.0 sat v dd = 5.0v ad131 t cnv conversion time (not including acquisition time) (1) ?11?t ad set go/done bit to new data in a/d result register ad132* t acq acquisition time 11.5 ? s ad133* t amp amplifier settling time ? ? 5 s ad134 t go q4 to a/d clock start ? ? t osc /2 t osc /2 + t cy ? ? ? ? if the a/d clock source is selected as rc, a time of t cy is added before the a/d clock starts. this allows the sleep instruction to be executed. * these parameters are characterized but not tested. ? data in ?typ? column is at 5.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: adresh and adresl registers may be read on the following t cy cycle. 2: see section 9.3 ?a/d acquisition requirements? for minimum conditions.
? 2007 microchip technology inc. preliminary ds41291d-page 259 pic16f882/883/884/886/887 figure 17-10: pic16f882/883/884/886/887 a/d conversion timing (normal mode) figure 17-11: pic16f882/883/884/886/887 a/d conversion timing (sleep mode) ad131 ad130 bsf adcon0, go q4 a/d clk a/d data adres adif go sample old_data sampling stopped done new_data 987 3210 note 1: if the a/d clock source is selected as rc, a time of t cy is added before the a/d clock starts. this allows the sleep instruction to be executed. 1 t cy 6 ad134 (t osc /2 (1) ) 1 t cy ad132 ad132 ad131 ad130 bsf adcon0, go q4 a/d clk a/d data adres adif go sample old_data sampling stopped done new_data 9 7 3210 note 1: if the a/d clock source is selected as rc, a time of t cy is added before the a/d clock starts. this allows the sleep instruction to be executed. ad134 6 8 1 t cy (t osc /2 + t cy (1) ) 1 t cy
pic16f882/883/884/886/887 ds41291d-page 260 preliminary ? 2007 microchip technology inc. notes:
? 2007 microchip technology inc. preliminary ds41291d-page 261 pic16f882/883/884/886/887 18.0 dc and ac characteristics graphs and tables graphs are not available at this time.
pic16f882/883/884/886/887 ds41291d-page 262 preliminary ? 2007 microchip technology inc. notes:
? 2007 microchip technology inc. preliminary ds41291d-page 263 pic16f882/883/884/886/887 19.0 packaging information 19.1 package marking information 3 e 28-lead qfn xxxxxxxx xxxxxxxx yywwnnn example 16f886 /ml 0510017 28-lead soic (7.50 mm) xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxx yywwnnn example pic16f886/so 0510017 28-lead pdip xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx yywwnnn xxxxxxxxxxxxxxx example pic16f883 0510017 28-lead ssop xxxxxxxxxxxx xxxxxxxxxxxx yywwnnn example pic16f883 -i/ss 0510017 -i/p 3 e 3 e 3 e legend: xx...x customer-specific information y year code (last digit of calendar year) yy year code (last 2 digits of calendar year) ww week code (week of january 1 is week ?01?) nnn alphanumeric traceability code pb-free jedec designator for matte tin (sn) * this package is pb-free. the pb-free jedec designator ( ) can be found on the outer packaging for this package. note : in the event the full microchip part number cannot be marked on one line, it will be carried over to the next line, thus limiting the number of available characters for customer-specific information. 3 e 3 e
pic16f882/883/884/886/887 ds41291d-page 264 preliminary ? 2007 microchip technology inc. 19.1 package marking information (continued) 3 e 40-lead pdip xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx yywwnnn example pic16f885 0510017 xxxxxxxxxx 44-lead qfn xxxxxxxxxx xxxxxxxxxx yywwnnn pic16f887 example -i/ml 0510017 44-lead tqfp xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx yywwnnn example pic16f887 -i/pt 0510017 3 e 3 e -i/p legend: xx...x customer-specific information y year code (last digit of calendar year) yy year code (last 2 digits of calendar year) ww week code (week of january 1 is week ?01?) nnn alphanumeric traceability code pb-free jedec designator for matte tin (sn) * this package is pb-free. the pb-free jedec designator ( ) can be found on the outer packaging for this package. note : in the event the full microchip part number cannot be marked on one line, it will be carried over to the next line, thus limiting the number of available characters for customer-specific information. 3 e 3 e
? 2007 microchip technology inc. preliminary ds41291d-page 265 pic16f882/883/884/886/887 19.2 package details the following sections give the technical details of the packages. 28-lead skinny plastic dual in-line (sp or pj) ? 300 mil body [spdip] notes: 1. pin 1 visual index feature may vary, but must be located within the hatched area. 2. significant characteristic. 3. dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010" per side. 4. dimensioning and tolerancing per asme y14.5m. bsc: basic dimension. theoretically exact value shown without tolerances. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging units inches dimension limits min nom max number of pins n 28 pitch e .100 bsc top to seating plane a ? ? .200 molded package thickness a2 .120 .135 .150 base to seating plane a1 .015 ? ? shoulder to shoulder width e .290 .310 .335 molded package width e1 .240 .285 .295 overall length d 1.345 1.365 1.400 tip to seating plane l .110 .130 .150 lead thickness c .008 .010 .015 upper lead width b1 .040 .050 .070 lower lead width b .014 .018 .022 overall row spacing eb ? ? .430 note 1 n 12 d e1 e b c e l a2 e b b1 a1 a 3 microchip technology drawing c04-070 b
pic16f882/883/884/886/887 ds41291d-page 266 preliminary ? 2007 microchip technology inc. 28-lead plastic small outline (so or oi) ? wide, 7.50 mm body [soic] n otes: 1 . pin 1 visual index feature may vary, but must be located within the hatched area. 2 . significant characteristic. 3 . dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed 0.15 mm per side. 4 . dimensioning and tolerancing per asme y14.5m. bsc: basic dimension. theoretically exact value shown without tolerances. ref: reference dimension, usually without tolerance, for information purposes only. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging units millimeters dimension limits min nom max number of pins n 28 pitch e 1.27 bsc overall height a ? ? 2.65 molded package thickness a2 2.05 ? ? standoff a1 0.10 ? 0.30 overall width e 10.30 bsc molded package width e1 7.50 bsc overall length d 17.90 bsc chamfer (optional) h 0.25 ? 0.75 foot length l 0.40 ? 1.27 footprint l1 1.40 ref foot angle top 0 ? 8 lead thickness c 0.18 ? 0.33 lead width b 0.31 ? 0.51 mold draft angle top 5 ? 15 mold draft angle bottom 5 ? 15 c h h l l1 a2 a1 a note 1 12 3 b e e e1 d n microchip technology drawing c04-052 b
? 2007 microchip technology inc. preliminary ds41291d-page 267 pic16f882/883/884/886/887 28-lead plastic shrink small outline (ss) ? 5.30 mm body [ssop] n otes: 1 . pin 1 visual index feature may vary, but must be located within the hatched area. 2 . dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed 0.20 mm per side. 3 . dimensioning and tolerancing per asme y14.5m. bsc: basic dimension. theoretically exact value shown without tolerances. ref: reference dimension, usually without tolerance, for information purposes only. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging units millimeters dimension limits min nom max number of pins n 28 pitch e 0.65 bsc overall height a ? ? 2.00 molded package thickness a2 1.65 1.75 1.85 standoff a1 0.05 ? ? overall width e 7.40 7.80 8.20 molded package width e1 5.00 5.30 5.60 overall length d 9.90 10.20 10.50 foot length l 0.55 0.75 0.95 footprint l1 1.25 ref lead thickness c 0.09 ? 0.25 foot angle 0 4 8 lead width b 0.22 ? 0.38 l l1 c a2 a1 a e e1 d n 1 2 note 1 b e microchip technology drawing c04-073 b
pic16f882/883/884/886/887 ds41291d-page 268 preliminary ? 2007 microchip technology inc. 28-lead plastic quad flat, no lead package (mm) ? 6x6x0.9 mm body [qfn-s] w ith 0.40 mm contact length n otes: 1 . pin 1 visual index feature may vary, but must be located within the hatched area. 2 . package is saw singulated. 3 . dimensioning and tolerancing per asme y14.5m. bsc: basic dimension. theoretically exact value shown without tolerances. ref: reference dimension, usually without tolerance, for information purposes only. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging units millimeters dimension limits min nom max number of pins n 28 pitch e 0.65 bsc overall height a 0.80 0.90 1.00 standoff a1 0.00 0.02 0.05 contact thickness a3 0.20 ref overall width e 6.00 bsc exposed pad width e2 3.65 3.70 4.70 overall length d 6.00 bsc exposed pad length d2 3.65 3.70 4.70 contact width b 0.23 0.38 0.43 contact length l 0.30 0.40 0.50 contact-to-exposed pad k 0.20 ? ? d e 2 1 n e2 exposed pad 2 1 d2 n e b k l note 1 a 3 a a1 top view bottom view microchip technology drawing c04-124 b
? 2007 microchip technology inc. preliminary ds41291d-page 269 pic16f882/883/884/886/887 40-lead plastic dual in-line (p or pl) ? 600 mil body [pdip] n otes: 1 . pin 1 visual index feature may vary, but must be located within the hatched area. 2 . significant characteristic. 3 . dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010" per side. 4 . dimensioning and tolerancing per asme y14.5m. bsc: basic dimension. theoretically exact value shown without tolerances. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging units inches dimension limits min nom max number of pins n 40 pitch e .100 bsc top to seating plane a ? ? .250 molded package thickness a2 .125 ? .195 base to seating plane a1 .015 ? ? shoulder to shoulder width e .590 ? .625 molded package width e1 .485 ? .580 overall length d 1.980 ? 2.095 tip to seating plane l .115 ? .200 lead thickness c .008 ? .015 upper lead width b1 .030 ? .070 lower lead width b .014 ? .023 overall row spacing eb ? ? .700 n note 1 e1 d 12 3 a a1 b1 b e c e b e l a2 microchip technology drawing c04-016 b
pic16f882/883/884/886/887 ds41291d-page 270 preliminary ? 2007 microchip technology inc. 44-lead plastic quad flat, no lead package (ml) ? 8x8 mm body [qfn] n otes: 1 . pin 1 visual index feature may vary, but must be located within the hatched area. 2 . package is saw singulated. 3 . dimensioning and tolerancing per asme y14.5m. bsc: basic dimension. theoretically exact value shown without tolerances. ref: reference dimension, usually without tolerance, for information purposes only. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging units millimeters dimension limits min nom max number of pins n 44 pitch e 0.65 bsc overall height a 0.80 0.90 1.00 standoff a1 0.00 0.02 0.05 contact thickness a3 0.20 ref overall width e 8.00 bsc exposed pad width e2 6.30 6.45 6.80 overall length d 8.00 bsc exposed pad length d2 6.30 6.45 6.80 contact width b 0.25 0.30 0.38 contact length l 0.30 0.40 0.50 contact-to-exposed pad k 0.20 ? ? d exposed pad d2 e b k l e2 2 1 n note 1 2 1 e n bottom view top view a 3 a1 a microchip technology drawing c04-103 b
? 2007 microchip technology inc. preliminary ds41291d-page 271 pic16f882/883/884/886/887 44-lead plastic thin quad flatpack (pt) ? 10x10x1 mm body, 2.00 mm footprint [tqfp] n otes: 1 . pin 1 visual index feature may vary, but must be located within the hatched area. 2 . chamfers at corners are optional; size may vary. 3 . dimensions d1 and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed 0.25 mm per side. 4 . dimensioning and tolerancing per asme y14.5m. bsc: basic dimension. theoretically exact value shown without tolerances. ref: reference dimension, usually without tolerance, for information purposes only. note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging units millimeters dimension limits min nom max number of leads n 44 lead pitch e 0.80 bsc overall height a ? ? 1.20 molded package thickness a2 0.95 1.00 1.05 standoff a1 0.05 ? 0.15 foot length l 0.45 0.60 0.75 footprint l1 1.00 ref foot angle 0 3.5 7 overall width e 12.00 bsc overall length d 12.00 bsc molded package width e1 10.00 bsc molded package length d1 10.00 bsc lead thickness c 0.09 ? 0.20 lead width b 0.30 0.37 0.45 mold draft angle top 11 12 13 mold draft angle bottom 11 12 13 a e e1 d d1 e b note 1 note 2 n 12 3 c a1 l a2 l1 microchip technology drawing c04-076 b
pic16f882/883/884/886/887 ds41291d-page 272 preliminary ? 2007 microchip technology inc. notes:
? 2007 microchip technology inc. preliminary ds41291d-page 273 pic16f882/883/884/886/887 appendix a: data sheet revision history revision a (5/2006) initial release of this data sheet. revision b (7/2006) pin diagrams (44-pin qfn drawing); revised table 2- 1, addr. 1dh (ccp2con); section 3.0, 3.1; section 3.4.4.6; table 3; table 3-1 (ansel); table 3-3 (ccp2con); register 3-1; register 3.2; register 3-3; register 3-4; register 3-9; register 3-10; register 3- 11; register 3-12; register 3-14; table 3-5 (ansel); figure 3-5; figure 3-11; figure 8-2; figure 8-3; figure 9-1; register 9-1; section 9.1.4; example 10-4; figure 11-5; table 11-5 (p1m); section 11.5.2; section 11.5.7, number 4; table 11-7 (ccp2con); section 12.3.1 (para. 3); figure 12-6 (title); sections 14.2, 14.3 and 14.4 dc characteristics (max); table 14-4 (osccon); section 14.3 (tmr0); section 14.3.2 (tmr0). revision c section 19.0 packaging information: replaced package drawings and added note. added pic16f882 part number. replaced picmicro with pic. revision d replaced package drawings (rev. am); replaced development support section; revised product id section. appendix b: migrating from other pic ? devices this discusses some of the issues in migrating from other pic devices to the pic16f88x family of devices. b.1 pic16f87x to pic16f88x table b-1: feature comparison feature pic16f87x pic16f88x max operating speed 20 mhz 20 mhz max program memory (words) 8192 8192 sram (bytes) 368 368 a/d resolution 10-bit 10-bit data eeprom (bytes) 256 256 timers (8/16-bit) 2/1 2/1 oscillator modes 4 8 brown-out reset y y (2.1v/4v) software control option of wdt/bor ny internal pull-ups rb<7:4> rb<7:0>, mclr interrupt-on-change rb<7:4> rb<7:0> comparator 2 2 references cv ref cv ref and vp6 eccp/ccp 0/2 1/1 ultra low-power wake-up ny extended wdt n y intosc frequencies n 32 khz-8 mhz clock switching n y mssp standard w/slave address mask usart ausart eusart adc channels 8 14 note: this device has been designed to perform to the parameters of its data sheet. it has been tested to an electrical specification designed to determine its conformance with these parameters. due to process differences in the manufacture of this device, this device may have different performance characteristics than its earlier version. these differences may cause this device to perform differently in your application than the earlier version of this device.
pic16f882/883/884/886/887 ds41291d-page 274 preliminary ? 2007 microchip technology inc. notes:
? 2007 microchip technology inc. preliminary ds41291d-page 275 pic16f882/883/884/886/887 index a a/d specifications.................................................... 257, 258 absolute maximum ratings .............................................. 239 ac characteristics industrial and extended ............................................ 249 load conditions ........................................................ 248 ackstat ......................................................................... 194 ackstat status flag ...................................................... 194 adc .................................................................................... 99 acquisition requirements ......................................... 107 associated registers ................................................ 109 block diagram............................................................. 99 calculating acquisition time..................................... 107 channel selection..................................................... 100 configuration............................................................. 100 configuring interrupt ................................................. 103 conversion clock...................................................... 100 conversion procedure .............................................. 103 internal sampling switch (r ss ) impedance.............. 107 interrupts................................................................... 101 operation .................................................................. 102 operation during sleep ............................................ 102 port configuration ..................................................... 100 reference voltage (v ref )......................................... 100 result formatting...................................................... 102 source impedance.................................................... 107 special event trigger................................................ 102 starting an a/d conversion ...................................... 102 adcon0 register............................................................. 104 adcon1 register............................................................. 105 adresh register (adfm = 0) ......................................... 106 adresh register (adfm = 1) ......................................... 106 adresl register (adfm = 0).......................................... 106 adresl register (adfm = 1).......................................... 106 analog input connection considerations............................ 90 analog-to-digital converter. see adc ansel register.................................................................. 40 anselh register ............................................................... 48 assembler mpasm assembler................................................... 236 b baud rate generator ........................................................ 191 baudctl register ........................................................... 160 bf ..................................................................................... 194 bf status flag .................................................................. 194 block diagrams (ccp) capture mode operation ............................... 126 adc ............................................................................ 99 adc transfer function ............................................. 108 analog input model ............................................. 90, 108 baud rate generator................................................ 191 ccp pwm................................................................. 128 clock source............................................................... 61 comparator c1 ........................................................... 84 comparator c1 and adc voltage reference ............. 95 comparator c2 ........................................................... 84 compare ................................................................... 127 crystal operation ........................................................ 64 eusart receive ..................................................... 150 eusart transmit .................................................... 149 external rc mode....................................................... 65 fail-safe clock monitor (fscm)................................. 71 in-circuit serial programming connections ............. 224 interrupt logic........................................................... 217 mssp (i 2 c master mode)......................................... 189 mssp (i 2 c mode)..................................................... 185 mssp (spi mode) .................................................... 179 on-chip reset circuit............................................... 208 pic16f883/886 .......................................................... 14 pic16f884/887 .......................................................... 15 pwm (enhanced) ..................................................... 132 ra0 pins..................................................................... 42 ra1 pin ...................................................................... 43 ra2 pin ...................................................................... 43 ra3 pin ...................................................................... 44 ra4 pin ...................................................................... 44 ra5 pin ...................................................................... 45 ra6 pin ...................................................................... 45 ra7 pin ...................................................................... 46 rb0, rb1, rb2, rb3 pins.......................................... 50 rb4, rb5, rb6, rb7 pins.......................................... 51 rc0 pin ...................................................................... 54 rc1 pin ...................................................................... 54 rc2 pin ...................................................................... 54 rc3 pin ...................................................................... 55 rc4 pin ...................................................................... 55 rc5 pin ...................................................................... 55 rc6 pin ...................................................................... 56 rc7 pin ...................................................................... 56 rd0, rd1, rd2, rd3, rd4 pins................................ 58 rd5, rd6, rd7 pins .................................................. 58 re3 pin ...................................................................... 60 resonator operation .................................................. 64 timer1 ........................................................................ 76 timer2 ........................................................................ 81 tmr0/wdt prescaler ................................................ 73 watchdog timer (wdt)............................................ 220 break character (12-bit) transmit and receive ............... 167 brg .................................................................................. 191 brown-out reset (bor).................................................... 210 associated ................................................................ 211 specifications ........................................................... 253 timing and characteristics ....................................... 252 bus collision during a repeated start condition ............. 202 bus collision during a start condition .............................. 200 bus collision during a stop condition.............................. 203 c c compilers mplab c18.............................................................. 236 mplab c30.............................................................. 236 capture module. see enhanced capture/compare/pwm(eccp) capture/compare/pwm (ccp) associated registers w/ capture, compare and timer1........................................ 148 associated registers w/ pwm and timer2 .............. 148 capture mode........................................................... 126 ccp pin configuration ............................................. 126 compare mode......................................................... 127 ccp pin configuration ..................................... 127 software interrupt mode ........................... 126, 127 special event trigger ....................................... 127 timer1 mode selection............................. 126, 127 prescaler .................................................................. 126
pic16f882/883/884/886/887 ds41291d-page 276 preliminary ? 2007 microchip technology inc. pwm mode ............................................................... 128 duty cycle......................................................... 129 effects of reset................................................. 131 example pwm frequencies and resolutions, 20 mhz ................................ 130 example pwm frequencies and resolutions, 8 mhz................................... 130 operation in sleep mode .................................. 131 setup for operation........................................... 131 system clock frequency changes................... 131 pwm period .............................................................. 129 setup for pwm operation ......................................... 131 timer resources....................................................... 125 ccp1con (enhanced) register....................................... 124 ccp2con register .......................................................... 125 clock accuracy with asynchronous operation ................. 158 clock sources external modes ........................................................... 63 ec ....................................................................... 63 hs ....................................................................... 64 lp........................................................................ 64 ost..................................................................... 63 rc....................................................................... 65 xt ....................................................................... 64 internal modes ............................................................ 65 frequency selection ........................................... 67 hfintosc.......................................................... 65 hfintosc/lfintosc switch timing ............... 67 intosc .............................................................. 65 intoscio........................................................... 65 lfintosc .......................................................... 67 clock switching................................................................... 69 cm1con0 register ............................................................ 88 cm2con0 register ............................................................ 89 cm2con1 register ............................................................ 91 code examples a/d conversion ......................................................... 103 assigning prescaler to timer0 .................................... 74 assigning prescaler to wdt ....................................... 74 changing between capture prescalers .................... 126 indirect addressing ..................................................... 37 initializing porta....................................................... 39 initializing portb....................................................... 47 initializing portc....................................................... 53 initializing portd....................................................... 57 initializing porte....................................................... 59 loading the sspbuf register ................................. 180 saving status and w registers in ram ............... 219 ultra low-power wake-up initialization ...................... 41 write verify ............................................................... 120 writing to flash program memory ............................ 119 code protection ................................................................ 223 comparator c2out as t1 gate ............................................... 77, 91 effects of a reset........................................................ 87 operation .................................................................... 83 operation during sleep .............................................. 87 response time ........................................................... 85 specifications............................................................ 256 synchronizing cout w/timer1 .................................. 91 comparator module ............................................................ 83 associated registers .................................................. 97 c1 output state versus input conditions ................... 85 comparator voltage reference (cv ref ) response time ........................................................... 85 comparator voltage reference (cv ref )............................ 94 effects of a reset ....................................................... 87 specifications ........................................................... 256 compare module. see enhanced capture/compare/pwm (eccp) config1 register ........................................................... 206 config2 register ........................................................... 207 configuration bits ............................................................. 206 cpu features ................................................................... 205 customer change notification service............................. 283 customer notification service .......................................... 283 customer support............................................................. 283 d data eeprom memory.................................................... 111 associated registers ................................................ 121 code protection ........................................................ 120 reading .................................................................... 114 writing ...................................................................... 114 data memory ...................................................................... 22 dc characteristics extended .................................................................. 244 industrial ................................................................... 243 industrial and extended ............................ 241, 242, 245 development support ....................................................... 235 device overview................................................................. 13 e eccp. see enhanced capture/compare/pwm eccpas register............................................................. 141 eeadr register ............................................................... 112 eeadr registers ............................................................. 111 eeadrh registers........................................................... 111 eecon1 register..................................................... 111, 113 eecon2 register............................................................. 111 eedat register ............................................................... 112 eedath register............................................................. 112 eeprom data memory avoiding spurious write ........................................... 120 write verify ............................................................... 120 effects of reset pwm mode ............................................................... 131 electrical specifications .................................................... 239 enhanced capture/compare/pwm .................................. 123 enhanced capture/compare/pwm (eccp) enhanced pwm mode.............................................. 132 auto-restart ..................................................... 142 auto-shutdown.................................................. 141 direction change in full-bridge output mode.. 138 full-bridge application...................................... 136 full-bridge mode .............................................. 136 half-bridge application ..................................... 135 half-bridge application examples .................... 143 half-bridge mode.............................................. 135 output relationships (active-high and active-low)............................................... 133 output relationships diagram.......................... 134 programmable dead band delay..................... 143 shoot-through current...................................... 143 start-up considerations.................................... 140 specifications ........................................................... 255 timer resources ...................................................... 124 enhanced universal synchronous asynchronous receiver transmitter (eusart) .............................. 149 errata .................................................................................. 12 eusart ........................................................................... 149
? 2007 microchip technology inc. preliminary ds41291d-page 277 pic16f882/883/884/886/887 associated registers baud rate generator........................................ 161 asynchronous mode ................................................. 151 12-bit break transmit and receive .................. 167 associated registers receive..................................................... 157 transmit.................................................... 153 auto-wake-up on break ................................... 166 baud rate generator (brg) ............................ 161 clock accuracy ................................................. 158 receiver............................................................ 154 setting up 9-bit mode with address detect....... 156 transmitter........................................................ 151 baud rate generator (brg) auto baud rate detect ..................................... 165 baud rate error, calculating ............................ 161 baud rates, asynchronous modes .................. 162 formulas ........................................................... 161 high baud rate select (brgh bit) .................. 161 synchronous master mode ............................... 169, 173 associated registers receive..................................................... 172 transmit.................................................... 170 reception.......................................................... 171 transmission .................................................... 169 synchronous slave mode associated registers receive..................................................... 174 transmit.................................................... 173 reception.......................................................... 174 transmission .................................................... 173 f fail-safe clock monitor....................................................... 71 fail-safe condition clearing ....................................... 71 fail-safe detection ..................................................... 71 fail-safe operation..................................................... 71 reset or wake-up from sleep..................................... 71 firmware instructions........................................................ 225 flash program memory .................................................... 111 writing....................................................................... 117 fuses. see configuration bits g general call address support .......................................... 188 general purpose register file............................................ 22 i i 2 c (mssp module) ack pulse......................................................... 185, 186 addressing ................................................................ 186 read/write bit information (r/w bit) ........................ 186 reception.................................................................. 186 serial clock (rc3/sck/scl).................................... 186 slave mode ............................................................... 185 transmission............................................................. 186 i 2 c master mode reception.............................................. 194 i 2 c master mode repeated start condition timing.......... 193 i 2 c module acknowledge sequence timing................................ 197 baud rate generator................................................ 191 brg block diagram.................................................. 191 brg reset due to sda arbitration during start condition .................................................. 201 brg timing .............................................................. 191 bus collision acknowledge .................................................... 199 repeated start condition ................................. 202 repeated start condition timing (case1)........ 202 repeated start condition timing (case2)........ 202 start condition.................................................. 200 start condition timing .............................. 200, 201 stop condition .................................................. 203 stop condition timing (case 1) ....................... 203 stop condition timing (case 2) ....................... 203 bus collision timing .................................................. 199 clock arbitration ....................................................... 198 clock arbitration timing (master transmit) .............. 198 effect of a reset ....................................................... 198 general call address support.................................. 188 master mode............................................................. 189 master mode 7-bit reception timing........................ 196 master mode operation............................................ 190 master mode start condition timing ........................ 192 master mode support ............................................... 189 master mode transmission ...................................... 194 master mode transmit sequence ............................ 190 multi-master mode.................................................... 199 repeat start condition timing waveform ................ 193 sleep operation........................................................ 198 stop condition receive or transmit timing ............. 198 stop condition timing .............................................. 197 waveforms for 7-bit reception ................................. 187 waveforms for 7-bit transmission............................ 187 id locations...................................................................... 223 in-circuit debugger........................................................... 224 in-circuit serial programming (icsp)............................... 223 indirect addressing, indf and fsr registers..................... 37 instruction format............................................................. 225 instruction set................................................................... 225 addlw..................................................................... 227 addwf .................................................................... 227 andlw..................................................................... 227 andwf .................................................................... 227 bcf .......................................................................... 227 bsf........................................................................... 227 btfsc...................................................................... 227 btfss ...................................................................... 228 call......................................................................... 228 clrf ........................................................................ 228 clrw ....................................................................... 228 clrwdt .................................................................. 228 comf ....................................................................... 228 decf........................................................................ 228 decfsz ................................................................... 229 goto ....................................................................... 229 incf ......................................................................... 229 incfsz..................................................................... 229 iorlw...................................................................... 229 iorwf...................................................................... 229 movf ....................................................................... 230 movlw .................................................................... 230 movwf.................................................................... 230 nop.......................................................................... 230 retfie..................................................................... 231 retlw ..................................................................... 231 return................................................................... 231 rlf........................................................................... 232 rrf .......................................................................... 232 sleep ...................................................................... 232 sublw..................................................................... 232
pic16f882/883/884/886/887 ds41291d-page 278 preliminary ? 2007 microchip technology inc. subwf ..................................................................... 233 swapf ..................................................................... 233 xorlw ..................................................................... 233 xorwf..................................................................... 233 summary table......................................................... 226 intcon register ................................................................ 31 inter-integrated circuit. see i 2 c internal oscillator block .................................................... 250 intosc specifications.................................................... 251 internal sampling switch (r ss ) impedance ...................... 107 internet address................................................................ 283 interrupts ........................................................................... 216 adc .......................................................................... 103 associated registers ................................................ 218 context saving.......................................................... 219 interrupt-on-change.................................................... 47 portb interrupt-on-change .................................... 217 rb0/int .................................................................... 216 timer0 ....................................................................... 217 tmr1 .......................................................................... 78 intosc specifications............................................................ 250 intosc specifications ............................................. 250, 251 iocb register ..................................................................... 49 l load conditions ................................................................ 248 m master mode ..................................................................... 189 master mode support........................................................ 189 master synchronous serial port. see mssp mclr ................................................................................ 209 internal ...................................................................... 209 memory organization.......................................................... 21 data ............................................................................ 22 program ...................................................................... 21 microchip internet web site .............................................. 283 migrating from other pic devices ..................................... 273 mplab asm30 assembler, linker, librarian ................... 236 mplab icd 2 in-circuit debugger.................................... 237 mplab ice 2000 high-performance universal in-circuit emulator .................................................... 237 mplab ice 4000 high-performance universal in-circuit emulator .................................................... 237 mplab integrated development environment software .. 235 mplab pm3 device programmer..................................... 237 mplink object linker/mplib object librarian ................ 236 mssp ................................................................................ 175 block diagram (spi mode) ....................................... 179 i 2 c mode. see i 2 c spi mode .................................................................. 179 spi mode. see spi mssp module control registers ...................................................... 175 i 2 c operation ............................................................ 185 spi master mode ...................................................... 181 spi slave mode ........................................................ 182 multi-master communication, bus collision and bus arbitra- tion ............................................................................ 199 multi-master mode ............................................................ 199 o opcode field descriptions ............................................. 225 option register ................................................................ 30 option_reg register...................................................... 75 osccon register.............................................................. 62 oscillator associated registers ............................................ 72, 80 oscillator module ................................................................ 61 ec............................................................................... 61 hfintosc ................................................................. 61 hs............................................................................... 61 intosc ...................................................................... 61 intoscio .................................................................. 61 lfintosc .................................................................. 61 lp ............................................................................... 61 rc .............................................................................. 61 rcio........................................................................... 61 xt ............................................................................... 61 oscillator parameters ....................................................... 250 oscillator specifications.................................................... 249 oscillator start-up timer (ost) specifications ........................................................... 253 oscillator switching fail-safe clock monitor .............................................. 71 two-speed clock start-up.......................................... 69 osctune register............................................................ 66 p p1a/p1b/p1c/p1d. see enhanced capture/compare/pwm (eccp) .............................. 132 packaging ......................................................................... 263 marking ............................................................. 263, 264 pdip details ............................................................. 265 pcl and pclath............................................................... 37 stack........................................................................... 37 pcon register ........................................................... 36, 211 picstart plus development programmer..................... 238 pie1 register...................................................................... 32 pie2 register...................................................................... 33 pin diagram pic16f883/886, 28-pin (pdip, soic, ssop) .............. 3 pic16f883/886, 28-pin (qfn)...................................... 4 pic16f884/887, 40-pin (pdip) .................................... 6 pic16f884/887, 44-pin (qfn)...................................... 8 pic16f884/887, 44-pin (tqfp).................................. 10 pinout descriptions pic16f883/886 .......................................................... 16 pic16f884/887 .......................................................... 18 pir1 register ..................................................................... 34 pir2 register ..................................................................... 35 porta ............................................................................... 39 additional pin functions ............................................. 40 ansel register ................................................. 40 ultra low-power wake-up............................ 40, 41 associated registers .................................................. 46 pin descriptions and diagrams .................................. 42 ra0............................................................................. 42 ra1............................................................................. 43 ra2............................................................................. 43 ra3............................................................................. 44 ra4............................................................................. 44 ra5............................................................................. 45 ra6............................................................................. 45 ra7............................................................................. 46 specifications ........................................................... 251 porta register ................................................................. 39 portb ............................................................................... 47 additional pin functions ............................................. 47 anselh register............................................... 47
? 2007 microchip technology inc. preliminary ds41291d-page 279 pic16f882/883/884/886/887 weak pull-up ...................................................... 47 associated registers .................................................. 52 interrupt-on-change.................................................... 47 p1b/p1c/p1d. see enhanced capture/compare/pwm+ (eccp+) .................... 47 pin descriptions and diagrams................................... 50 rb0 ............................................................................. 50 rb1 ............................................................................. 50 rb2 ............................................................................. 50 rb3 ............................................................................. 50 rb4 ............................................................................. 51 rb5 ............................................................................. 51 rb6 ............................................................................. 51 rb7 ............................................................................. 51 portb register ................................................................. 48 portc ............................................................................... 53 associated registers .................................................. 56 p1a. see enhanced capture/compare/pwm+ (eccp+) ............................................................. 53 rc0............................................................................. 54 rc1............................................................................. 54 rc2............................................................................. 54 rc3............................................................................. 55 rc3 pin..................................................................... 186 rc4............................................................................. 55 rc5............................................................................. 55 rc6............................................................................. 56 rc7............................................................................. 56 specifications............................................................ 251 portc register ................................................................. 53 portd ............................................................................... 57 associated registers .................................................. 58 p1b/p1c/p1d. see enhanced capture/compare/pwm+ (eccp+) .................... 57 rd0, rd1, rd2, rd3, rd4 ........................................ 58 rd5............................................................................. 58 rd6............................................................................. 58 rd7............................................................................. 58 portd register ................................................................. 57 porte................................................................................ 59 associated registers .................................................. 60 re0 ............................................................................. 60 re1 ............................................................................. 60 re2 ............................................................................. 60 re3 ............................................................................. 60 porte register ................................................................. 59 power-down mode (sleep) ............................................... 222 power-on reset (por) ..................................................... 209 power-up timer (pwrt) .................................................. 209 specifications............................................................ 253 precision internal oscillator parameters........................... 251 prescaler shared wdt/timer0 ................................................... 74 switching prescaler assignment................................. 74 program memory ................................................................ 21 map and stack ............................................................ 21 map and stack (pic16f883/884) ............................... 21 map and stack (pic16f886/887) ............................... 21 programming, device instructions .................................... 225 pstrcon register .......................................................... 145 pulse steering................................................................... 145 pwm (eccp module) pulse steering........................................................... 145 steering synchronization .......................................... 147 pwm mode. see enhanced capture/compare/pwm ...... 132 pwm1con register......................................................... 144 r rcreg............................................................................. 156 rcsta register ............................................................... 159 reader response............................................................. 284 read-modify-write operations ......................................... 225 register rcreg register ...................................................... 165 registers adcon0 (adc control 0) ........................................ 104 adcon1 (adc control 1) ........................................ 105 adresh (adc result high) with adfm = 0) .......... 106 adresh (adc result high) with adfm = 1) .......... 106 adresl (adc result low) with adfm = 0)............ 106 adresl (adc result low) with adfm = 1)............ 106 ansel (analog select) .............................................. 40 anselh (analog select high) ................................... 48 baudctl (baud rate control)................................ 160 ccp1con (enhanced ccp1 control) ..................... 124 ccp2con (ccp2 control) ...................................... 125 cm1con0 (c1 control) ............................................. 88 cm2con0 (c2 control) ............................................. 89 cm2con1 (c2 control) ............................................. 91 config1 (configuration word register 1).............. 206 config2 (configuration word register 2).............. 207 eccpas (enhanced ccp auto-shutdown control) . 141 eeadr (eeprom address) .................................... 112 eecon1 (eeprom control 1) ................................ 113 eedat (eeprom data) .......................................... 112 eedath (eeprom data) ....................................... 112 intcon (interrupt control) ........................................ 31 iocb (interrupt-on-change portb).......................... 49 option_reg (option)..................................... 30, 75 osccon (oscillator control)..................................... 62 osctune (oscillator tuning).................................... 66 pcon (power control register)................................. 36 pcon (power control) ............................................. 211 pie1 (peripheral interrupt enable 1) .......................... 32 pie2 (peripheral interrupt enable 2) .......................... 33 pir1 (peripheral interrupt register 1) ........................ 34 pir2 (peripheral interrupt request 2) ........................ 35 porta ....................................................................... 39 portb ....................................................................... 48 portc ....................................................................... 53 portd ....................................................................... 57 porte ....................................................................... 59 pstrcon (pulse steering control)......................... 145 pwm1con (enhanced pwm control) ..................... 144 rcsta (receive status and control) ...................... 159 reset values ............................................................ 213 reset values (special registers)............................... 215 special function register map pic16f883/884 ............................................ 23, 24 pic16f886/887 .................................................. 25 special function registers......................................... 22 special register summary bank 0 ................................................................ 26 bank 1 ................................................................ 27 bank 2 ................................................................ 28 bank 3 ................................................................ 28 srcon (sr latch control)........................................ 93 sspcon (mssp control 1) ..................................... 177 sspcon2 (ssp control 2) ...................................... 178 sspmsk (ssp mask) .............................................. 204 sspstat (ssp status) ........................................... 176
pic16f882/883/884/886/887 ds41291d-page 280 preliminary ? 2007 microchip technology inc. status ...................................................................... 29 t1con ........................................................................ 79 t2con ........................................................................ 82 trisa (tri-state porta) ........................................... 39 trisb (tri-state portb) ........................................... 48 trisc (tri-state portc) .......................................... 53 trisd (tri-state portd) .......................................... 57 trise (tri-state porte) ........................................... 59 txsta (transmit status and control) ...................... 158 vrcon (voltage reference control) ......................... 97 wdtcon (watchdog timer control)........................ 221 wpub (weak pull-up portb) ................................... 49 reset................................................................................. 208 revision history ................................................................ 273 s sck................................................................................... 179 sdi .................................................................................... 179 sdo .................................................................................. 179 serial clock, sck.............................................................. 179 serial data in, sdi ............................................................ 179 serial data out, sdo........................................................ 179 serial peripheral interface. see spi shoot-through current ...................................................... 143 slave mode general call address sequence................... 188 slave select synchronization............................................ 182 slave select, ss ............................................................... 179 sleep ................................................................................. 222 wake-up.................................................................... 222 wake-up using interrupts ......................................... 222 software simulator (mplab sim)..................................... 236 spbrg.............................................................................. 161 spbrgh ........................................................................... 161 special event trigger........................................................ 102 special function registers ................................................. 22 spi master mode ............................................................. 181 serial clock............................................................... 179 serial data in ............................................................ 179 serial data out ......................................................... 179 slave select .............................................................. 179 spi clock ................................................................... 181 spi mode .................................................................. 179 spi bus modes ................................................................. 184 spi mode associated registers with spi operation ................. 184 bus mode compatibility ............................................ 184 effects of a reset...................................................... 184 enabling spi i/o ....................................................... 180 operation .................................................................. 179 sleep operation ........................................................ 184 spi module slave mode ............................................................... 182 slave select synchronization ................................... 182 slave synchronization timing................................... 182 slave timing with cke = 0 ....................................... 183 slave timing with cke = 1 ....................................... 183 srcon register................................................................. 93 ss ..................................................................................... 179 ssp sspbuf.................................................................... 181 sspsr ...................................................................... 181 sspcon register............................................................. 177 sspcon2 register........................................................... 178 sspmsk register............................................................. 204 sspov.............................................................................. 194 sspov status flag .......................................................... 194 sspstat register ........................................................... 176 r/w bit ..................................................................... 186 status register ............................................................... 29 t t1con register ................................................................. 79 t2con register ................................................................. 82 thermal considerations.................................................... 247 time-out sequence .......................................................... 211 timer0................................................................................. 73 associated registers .................................................. 75 external clock............................................................. 74 interrupt ...................................................................... 75 operation .............................................................. 73, 76 specifications ........................................................... 254 t0cki ......................................................................... 74 timer1................................................................................. 76 associated registers .................................................. 80 asynchronous counter mode ..................................... 77 reading and writing ........................................... 77 interrupt ...................................................................... 78 modes of operation .................................................... 76 operation during sleep .............................................. 78 oscillator..................................................................... 77 prescaler .................................................................... 77 specifications ........................................................... 254 timer1 gate inverting gate ..................................................... 77 selecting source .......................................... 77, 91 sr latch............................................................. 92 synchronizing cout w/timer1 .......................... 91 tmr1h register ......................................................... 76 tmr1l register.......................................................... 76 timer2 associated registers .................................................. 82 timers timer1 t1con ............................................................... 79 timer2 t2con ............................................................... 82 timing diagrams a/d conversion......................................................... 259 a/d conversion (sleep mode) .................................. 259 acknowledge sequence timing ............................... 197 asynchronous reception.......................................... 156 asynchronous transmission..................................... 152 asynchronous transmission (back to back) ............ 152 auto wake-up bit (wue) during normal operation . 166 auto wake-up bit (wue) during sleep .................... 167 automatic baud rate calibration.............................. 165 baud rate generator with clock arbitration............. 191 brg reset due to sda arbitration .......................... 201 brown-out reset (bor)............................................ 252 brown-out reset situations ...................................... 210 bus collision start condition timing ...................................... 200 bus collision during a repeated start condition (case 1)............................................ 202 bus collision during a repeated start condition (case2)............................................................. 202 bus collision during a start condition (scl = 0) ..... 201 bus collision during a stop condition...................... 203 bus collision for transmit and acknowledge ........... 199 clkout and i/o ...................................................... 251 clock timing ............................................................. 249
? 2007 microchip technology inc. preliminary ds41291d-page 281 pic16f882/883/884/886/887 comparator output ..................................................... 83 enhanced capture/compare/pwm (eccp) ............. 255 fail-safe clock monitor (fscm) ................................. 72 full-bridge pwm output ........................................... 137 half-bridge pwm output .................................. 135, 143 i 2 c master mode first start bit timing ..................... 192 i 2 c master mode reception timing.......................... 196 i 2 c master mode transmission timing..................... 195 i 2 c module bus collision transmit timing ........................................ 199 int pin interrupt........................................................ 218 internal oscillator switch timing................................. 68 master mode transmit clock arbitration................... 198 pwm auto-shutdown auto-restart enabled ......................................... 142 firmware restart .............................................. 142 pwm direction change ............................................ 138 pwm direction change at near 100% duty cycle ... 139 pwm output (active-high)........................................ 133 pwm output (active-low) ........................................ 134 repeat start condition.............................................. 193 reset, wdt, ost and power-up timer ................... 252 send break character sequence ............................. 168 slave synchronization .............................................. 182 spi mode timing (master mode) spi mode master mode timing diagram .......................... 181 spi mode timing (slave mode with cke = 0) .......... 183 spi mode timing (slave mode with cke = 1) .......... 183 stop condition receive or transmit ......................... 198 synchronous reception (master mode, sren) ....... 172 synchronous transmission....................................... 170 synchronous transmission (through txen) ........... 170 time-out sequence case 1 .............................................................. 212 case 2 .............................................................. 212 case 3 .............................................................. 212 timer0 and timer1 external clock ........................... 254 timer1 incrementing edge.......................................... 78 two speed start-up .................................................... 70 wake-up from interrupt ............................................. 223 timing parameter symbology........................................... 248 trisa ................................................................................. 39 trisa register ................................................................... 39 trisb ................................................................................. 47 trisb register ................................................................... 48 trisc ................................................................................. 53 trisc register................................................................... 53 trisd ................................................................................. 57 trisd register................................................................... 57 trise ................................................................................. 59 trise register ................................................................... 59 two-speed clock start-up mode ........................................ 69 txreg.............................................................................. 151 txsta register ................................................................ 158 brgh bit .................................................................. 161 u ultra low-power wake-up ................................ 16, 18, 40, 41 v voltage reference. see comparator voltage reference (cv ref ) voltage references associated registers.................................................. 97 vp6 stabilization ........................................................ 94 v ref . s ee adc reference voltage w wake-up on break ............................................................ 166 wake-up using interrupts ................................................. 222 watchdog timer (wdt).................................................... 220 associated registers................................................ 221 clock source ............................................................ 220 modes....................................................................... 220 period ....................................................................... 220 specifications ........................................................... 253 waveform for slave mode general call address sequence ................................................................. 188 wcol ............................................................... 192, 194, 197 wcol status flag............................................ 192, 194, 197 wdtcon register ........................................................... 221 wpub register................................................................... 49 www address ................................................................. 283 www, on-line support .................... ................................. 12
pic16f882/883/884/886/887 ds41291d-page 282 preliminary ? 2007 microchip technology inc. notes:
? 2007 microchip technology inc. preliminary ds41291d-page 283 pic16f882/883/884/886/887 the microchip web site microchip provides online support via our www site at www.microchip.com. this web site is used as a means to make files and information easily available to customers. accessible by using your favorite internet browser, the web site contains the following information: ? product support ? data sheets and errata, application notes and sample programs, design resources, user?s guides and hardware support documents, latest software releases and archived software ? general technical support ? frequently asked questions (faq), technical support requests, online discussion groups, microchip consultant program member listing ? business of microchip ? product selector and ordering guides, latest microchip press releases, listing of seminars and events, listings of microchip sales offices, distributors and factory representatives customer change notification service microchip?s customer notification service helps keep customers current on microchip products. subscribers will receive e-mail notification whenever there are changes, updates, revisions or errata related to a specified product family or development tool of interest. to register, access the microchip web site at www.microchip.com, click on customer change notification and follow the registration instructions. customer support users of microchip products can receive assistance through several channels: ? distributor or representative ? local sales office ? field application engineer (fae) ? technical support ? development systems information line customers should contact their distributor, representative or field application engineer (fae) for support. local sales offices are also available to help customers. a listing of sales offices and locations is included in the back of this document. technical support is available through the web site at: http://support.microchip.com
pic16f882/883/884/886/887 ds41291d-page 284 preliminary ? 2007 microchip technology inc. reader response it is our intention to provide you with the best documentation possible to ensure successful use of your microchip prod- uct. if you wish to provide your comments on organization, clarity, subject matter, and ways in which our documentation can better serve you, please fax your comments to the technical publications manager at (480) 792-4150. please list the following information, and use this outline to provide us with your comments about this document. to : technical publications manager re: reader response total pages sent ________ from: name company address city / state / zip / country telephone: (_______) _________ - _________ application (optional): would you like a reply? y n device: literature number: questions: fax: (______) _________ - _________ ds41291d pic16f882/883/884/886/887 1. what are the best features of this document? 2. how does this document meet your hardware and software development needs? 3. do you find the organization of this document easy to follow? if not, why? 4. what additions to the document do you think would enhance the structure and subject? 5. what deletions from the document could be made without affecting the overall usefulness? 6. is there any incorrect or misleading information (what and where)? 7. how would you improve this document?
? 2007 microchip technology inc. preliminary ds41291d-page 285 pic16f882/883/884/886/887 product identification system to order or obtain information, e. g., on pricing or delivery, refer to the factory or the listed sales office . part no. x /xx xxx pattern package temperature range device device: pic16f883f (1) , pic16f883ft (1, 2) , pic16f884f (1) , pic16f884ft (1, 2) , pic16f886f (1) , pic16f886ft (1, 2) , pic16f887f (1) , pic16f887ft (1, 2) v dd range 2.0v to 5.5v temperature range: i= -40 c to +85 c (industrial) e= -40 c to +125 c (extended) package: ml = quad flat no leads (qfn) p = plastic dip pt = plastic thin-quad flatpack (tqfp) so = plastic small outline (soic) (7.50 mm) ss = plastic shrink small outline pattern: qtp, sqtp, code or special requirements (blank otherwise) examples: a) pic16f883-e/p 301 = extended temp., pdip package, 20 mhz, qtp pattern #301 b) pic16f883-i/so = industrial temp., soic package, 20 mhz note 1: f = standard voltage range 2: t = in tape and reel ssop, soic and qfn packages only.
ds41291d-page 286 preliminary ? 2007 microchip technology inc. americas corporate office 2355 west chandler blvd. chandler, az 85224-6199 tel: 480-792-7200 fax: 480-792-7277 technical support: http://support.microchip.com web address: www.microchip.com atlanta duluth, ga tel: 678-957-9614 fax: 678-957-1455 boston westborough, ma tel: 774-760-0087 fax: 774-760-0088 chicago itasca, il tel: 630-285-0071 fax: 630-285-0075 dallas addison, tx tel: 972-818-7423 fax: 972-818-2924 detroit farmington hills, mi tel: 248-538-2250 fax: 248-538-2260 kokomo kokomo, in tel: 765-864-8360 fax: 765-864-8387 los angeles mission viejo, ca tel: 949-462-9523 fax: 949-462-9608 santa clara santa clara, ca tel: 408-961-6444 fax: 408-961-6445 toronto mississauga, ontario, canada tel: 905-673-0699 fax: 905-673-6509 asia/pacific asia pacific office suites 3707-14, 37th floor tower 6, the gateway habour city, kowloon hong kong tel: 852-2401-1200 fax: 852-2401-3431 australia - sydney tel: 61-2-9868-6733 fax: 61-2-9868-6755 china - beijing tel: 86-10-8528-2100 fax: 86-10-8528-2104 china - chengdu tel: 86-28-8665-5511 fax: 86-28-8665-7889 china - fuzhou tel: 86-591-8750-3506 fax: 86-591-8750-3521 china - hong kong sar tel: 852-2401-1200 fax: 852-2401-3431 china - qingdao tel: 86-532-8502-7355 fax: 86-532-8502-7205 china - shanghai tel: 86-21-5407-5533 fax: 86-21-5407-5066 china - shenyang tel: 86-24-2334-2829 fax: 86-24-2334-2393 china - shenzhen tel: 86-755-8203-2660 fax: 86-755-8203-1760 china - shunde tel: 86-757-2839-5507 fax: 86-757-2839-5571 china - wuhan tel: 86-27-5980-5300 fax: 86-27-5980-5118 china - xian tel: 86-29-8833-7250 fax: 86-29-8833-7256 asia/pacific india - bangalore tel: 91-80-4182-8400 fax: 91-80-4182-8422 india - new delhi tel: 91-11-4160-8631 fax: 91-11-4160-8632 india - pune tel: 91-20-2566-1512 fax: 91-20-2566-1513 japan - yokohama tel: 81-45-471- 6166 fax: 81-45-471-6122 korea - gumi tel: 82-54-473-4301 fax: 82-54-473-4302 korea - seoul tel: 82-2-554-7200 fax: 82-2-558-5932 or 82-2-558-5934 malaysia - penang tel: 60-4-646-8870 fax: 60-4-646-5086 philippines - manila tel: 63-2-634-9065 fax: 63-2-634-9069 singapore tel: 65-6334-8870 fax: 65-6334-8850 taiwan - hsin chu tel: 886-3-572-9526 fax: 886-3-572-6459 taiwan - kaohsiung tel: 886-7-536-4818 fax: 886-7-536-4803 taiwan - taipei tel: 886-2-2500-6610 fax: 886-2-2508-0102 thailand - bangkok tel: 66-2-694-1351 fax: 66-2-694-1350 europe austria - wels tel: 43-7242-2244-39 fax: 43-7242-2244-393 denmark - copenhagen tel: 45-4450-2828 fax: 45-4485-2829 france - paris tel: 33-1-69-53-63-20 fax: 33-1-69-30-90-79 germany - munich tel: 49-89-627-144-0 fax: 49-89-627-144-44 italy - milan tel: 39-0331-742611 fax: 39-0331-466781 netherlands - drunen tel: 31-416-690399 fax: 31-416-690340 spain - madrid tel: 34-91-708-08-90 fax: 34-91-708-08-91 uk - wokingham tel: 44-118-921-5869 fax: 44-118-921-5820 w orldwide s ales and s ervice 12/08/06


▲Up To Search▲   

 
Price & Availability of PIC16F883T-EPSQTP

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X